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)

Instance Method Details

- (Object) load(csv_file, options = {}, &block)

Loads a CSV file directly into a Table using the FasterCSV library.

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" })


232
233
234
# File 'lib/ruport/data/table.rb', line 232

def load(csv_file, options={},&block)
  get_table_from_csv(:foreach, csv_file, options,&block)
end

- (Object) parse(string, options = {}, &block)

Creates a Table from a CSV string using FasterCSV. See Table.load for additional examples.

table = Table.parse("a,b,c\n1,2,3\n4,5,6\n")


241
242
243
# File 'lib/ruport/data/table.rb', line 241

def parse(string, options={},&block)
  get_table_from_csv(:parse,string,options,&block)
end