A CSV document representation.

Introduced properties

fun add_record(objs: Object...)

csv :: CsvDocument :: add_record

Adds a new record to document containing the values in objs
init defaultinit(header: nullable Array[String], records: nullable Array[Array[String]])

csv :: CsvDocument :: defaultinit

fun header: Array[String]

csv :: CsvDocument :: header

The header.
fun header=(header: nullable Array[String])

csv :: CsvDocument :: header=

The header.
fun load_from(stream: Reader, has_header: nullable Bool, skip_empty: nullable Bool)

csv :: CsvDocument :: load_from

Load from the specified stream.
fun records: Array[Array[String]]

csv :: CsvDocument :: records

The list of the records.
fun records=(records: nullable Array[Array[String]])

csv :: CsvDocument :: records=

The list of the records.

Redefined properties

redef type SELF: CsvDocument

csv $ CsvDocument :: SELF

Type of this instance, automatically specialized in every class
redef fun write_to(stream: Writer)

csv $ CsvDocument :: write_to

Write itself to a stream

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
fun add_record(objs: Object...)

csv :: CsvDocument :: add_record

Adds a new record to document containing the values in objs
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
init defaultinit(header: nullable Array[String], records: nullable Array[Array[String]])

csv :: CsvDocument :: defaultinit

fun delimiter: Char

csv :: CsvStream :: delimiter

The character that delimits escaped value.
fun delimiter=(delimiter: Char)

csv :: CsvStream :: delimiter=

The character that delimits escaped value.
fun eol: String

csv :: CsvStream :: eol

The character that ends a record (end of line).
fun eol=(eol: String)

csv :: CsvStream :: eol=

The character that ends a record (end of line).
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
fun header: Array[String]

csv :: CsvDocument :: header

The header.
fun header=(header: nullable Array[String])

csv :: CsvDocument :: header=

The header.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun load_from(stream: Reader, has_header: nullable Bool, skip_empty: nullable Bool)

csv :: CsvDocument :: load_from

Load from the specified stream.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun records: Array[Array[String]]

csv :: CsvDocument :: records

The list of the records.
fun records=(records: nullable Array[Array[String]])

csv :: CsvDocument :: records=

The list of the records.
fun separator: Char

csv :: CsvStream :: separator

The character that split each cell in a record.
fun separator=(separator: Char)

csv :: CsvStream :: separator=

The character that split each cell in a record.
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
abstract fun write_to(stream: Writer)

core :: Writable :: write_to

Write itself to a stream
fun write_to_bytes: Bytes

core :: Writable :: write_to_bytes

Like write_to but return a new Bytes (may be quite large)
fun write_to_file(filepath: String)

core :: Writable :: write_to_file

Like write_to but take care of creating the file
fun write_to_string: String

core :: Writable :: write_to_string

Like write_to but return a new String (may be quite large).
package_diagram csv::CsvDocument CsvDocument core::Writable Writable csv::CsvDocument->core::Writable csv::CsvStream CsvStream csv::CsvDocument->csv::CsvStream core::Object Object core::Writable->core::Object csv::CsvStream->core::Object ...core::Object ... ...core::Object->core::Object

Ancestors

interface Object

core :: Object

The root of the class hierarchy.

Parents

abstract class CsvStream

csv :: CsvStream

Shared properties by all CSV-related classes
interface Writable

core :: Writable

Things that can be efficienlty written to a Writer

Class definitions

csv $ CsvDocument
# A CSV document representation.
class CsvDocument
	super Writable
	super CsvStream

	# The header.
	#
	# Contains the name of all fields in this table.
	var header = new Array[String] is writable, optional

	# The list of the records.
	#
	# All records must have the same length than `header`.
	var records = new Array[Array[String]] is writable, optional

	# Adds a new record to document containing the values in `objs`
	fun add_record(objs: Object...) do
		var ln = new Array[String].with_capacity(objs.length)
		for i in objs do ln.add(i.to_s)
		records.add ln
	end

	redef fun write_to(stream) do
		var s = new CsvWriter(stream)
		s.separator = separator
		s.eol = eol
		s.delimiter = delimiter
		if not header.is_empty then
			s.write_line header
		end
		s.write_lines(records)
	end

	# Load from the specified stream.
	#
	# Parameters:
	#
	# * `stream`: Input stream.
	# * `has_header`: Is the first record the header? - defaults to true
	# * `skip_empty`: Do we skip the empty lines? - defaults to true
	fun load_from(stream: Reader, has_header: nullable Bool, skip_empty: nullable Bool) do
		if has_header == null then has_header = true
		if skip_empty == null then skip_empty = true
		var reader = new CsvReader(stream)
		reader.separator = separator
		reader.eol = eol
		reader.delimiter = delimiter
		reader.skip_empty = skip_empty
	end
end
lib/csv/csv.nit:116,1--165,3