Module: Ruport::Data::Table::FromCSV
- Included in:
- Ruport::Data::Table
- Defined in:
- lib/ruport/data/table.rb
Overview
Overview
This module provides facilities for creating tables from csv data.
Instance Method Summary collapse
-
#load(csv_file, options = {}, &block) ⇒ Object
Loads a CSV file directly into a Table.
-
#parse(string, options = {}, &block) ⇒ Object
Creates a Table from a CSV string.
Instance Method Details
#load(csv_file, options = {}, &block) ⇒ Object
Loads a CSV file directly into a Table.
Example:
# treat first row as column_names
table = Table.load('mydata.csv')
# do not assume the data has column_names
table = Table.load('mydata.csv',:has_names => false)
# pass in FasterCSV options, such as column separators
table = Table.load('mydata.csv',:csv_options => { :col_sep => "\t" })
238 239 240 |
# File 'lib/ruport/data/table.rb', line 238 def load(csv_file, ={},&block) get_table_from_csv(:foreach, csv_file, ,&block) end |
#parse(string, options = {}, &block) ⇒ Object
Creates a Table from a CSV string. See Table.load for additional examples.
table = Table.parse("a,b,c\n1,2,3\n4,5,6\n")
247 248 249 |
# File 'lib/ruport/data/table.rb', line 247 def parse(string, ={},&block) get_table_from_csv(:parse,string,,&block) end |