Class: TableData::Presenters::CSV
Constant Summary
collapse
- OptionMapping =
{
column_separator: :col_sep,
row_separator: :row_sep,
quote_char: :quote_character,
}
Instance Attribute Summary
#table
Instance Method Summary
collapse
#initialize, present
Instance Method Details
#csv_options ⇒ Object
15
16
17
18
19
20
|
# File 'lib/tabledata/presenters/csv.rb', line 15
def csv_options
options = ::CSV::DEFAULT_OPTIONS.dup
@options.each do |k,v| options[OptionMapping.fetch(k,k)] = v end
options
end
|
#string(options = nil) ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/tabledata/presenters/csv.rb', line 22
def string(options=nil)
::CSV.generate(csv_options) do |csv|
@table.each_row do |row|
csv << row.to_a
end
end
end
|
#write(path, options = nil) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/tabledata/presenters/csv.rb', line 30
def write(path, options=nil)
::CSV.open(path, 'wb', csv_options) do |csv|
@table.each_row do |row|
csv << row.to_a
end
end
end
|