Property definitions

csv $ CsvDocument :: defaultinit
# 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