Module: Workbook::Writers::CsvTableWriter
- Included in:
- Table
- Defined in:
- lib/workbook/writers/csv_table_writer.rb
Instance Method Summary collapse
-
#to_csv(options = {}) ⇒ String
Output the current workbook to CSV format.
-
#write_to_csv(filename = "#{title}.csv", options = {}) ⇒ String
Write the current workbook to CSV format.
Instance Method Details
#to_csv(options = {}) ⇒ String
Output the current workbook to CSV format
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/workbook/writers/csv_table_writer.rb', line 14 def to_csv ={} csv = "" = {}.merge self.each_with_index do |r, ri| line=nil begin line = CSV::generate_line(r.collect{|c| c.value if c},{:row_sep=>""}) rescue TypeError line = CSV::generate_line(r.collect{|c| c.value if c}) end csv += "#{line}\n" end csv end |
#write_to_csv(filename = "#{title}.csv", options = {}) ⇒ String
Write the current workbook to CSV format
34 35 36 37 |
# File 'lib/workbook/writers/csv_table_writer.rb', line 34 def write_to_csv filename="#{title}.csv", ={} File.open(filename, 'w') {|f| f.write(to_csv()) } return filename end |