Class: AsCSV::CSVBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/as_csv/csv_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(records, options = {}) ⇒ CSVBuilder

Returns a new instance of CSVBuilder.



7
8
9
10
11
# File 'lib/as_csv/csv_builder.rb', line 7

def initialize(records, options={})
  @records = Array(records)
  @options = options
  validate
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/as_csv/csv_builder.rb', line 5

def options
  @options
end

#recordsObject (readonly)

Returns the value of attribute records.



5
6
7
# File 'lib/as_csv/csv_builder.rb', line 5

def records
  @records
end

Instance Method Details

#to_csvObject



13
14
15
# File 'lib/as_csv/csv_builder.rb', line 13

def to_csv
  rows.collect { |row| CSV.generate_line row }.join
end