Class: Roo::Csv
- Inherits:
-
GenericSpreadsheet
- Object
- GenericSpreadsheet
- Roo::Csv
- Defined in:
- lib/roo/csv.rb
Overview
The Csv class can read csv files (must be separated with commas) which then can be handled like spreadsheets. This means you can access cells like A5 within these files. The Csv class provides only string objects. If you want conversions to other types you have to do it yourself.
Constant Summary
Constants inherited from GenericSpreadsheet
GenericSpreadsheet::TEMP_PREFIX
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Attributes inherited from GenericSpreadsheet
#default_sheet, #header_line, #headers
Instance Method Summary collapse
- #cell(row, col, sheet = nil) ⇒ Object
- #cell_postprocessing(row, col, value) ⇒ Object
- #celltype(row, col, sheet = nil) ⇒ Object
-
#initialize(filename, packed = nil, file_warning = :error, tmpdir = nil) ⇒ Csv
constructor
A new instance of Csv.
-
#sheets ⇒ Object
Returns an array with the names of the sheets.
Methods inherited from GenericSpreadsheet
#column, #each, #each_with_pagename, #empty?, #find, #first_column, #first_column_as_letter, #first_row, #info, #last_column, #last_column_as_letter, #last_row, #longest_sheet, #method_missing, #parse, #reload, #row, #row_with, #set, #sheet, #to_csv, #to_matrix, #to_xml, #to_yaml
Constructor Details
#initialize(filename, packed = nil, file_warning = :error, tmpdir = nil) ⇒ Csv
Returns a new instance of Csv.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/roo/csv.rb', line 11 def initialize(filename, packed=nil, file_warning=:error, tmpdir=nil) @filename = filename @cell = Hash.new @cell_type = Hash.new @cells_read = Hash.new @first_row = Hash.new @last_row = Hash.new @first_column = Hash.new @last_column = Hash.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Roo::GenericSpreadsheet
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
22 23 24 |
# File 'lib/roo/csv.rb', line 22 def filename @filename end |
Instance Method Details
#cell(row, col, sheet = nil) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/roo/csv.rb', line 30 def cell(row, col, sheet=nil) sheet ||= @default_sheet read_cells(sheet) unless @cells_read[sheet] row,col = normalize(row,col) @cell[[row,col]] end |
#cell_postprocessing(row, col, value) ⇒ Object
44 45 46 |
# File 'lib/roo/csv.rb', line 44 def cell_postprocessing(row,col,value) value end |
#celltype(row, col, sheet = nil) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/roo/csv.rb', line 37 def celltype(row, col, sheet=nil) sheet ||= @default_sheet read_cells(sheet) unless @cells_read[sheet] row,col = normalize(row,col) @cell_type[[row,col]] end |
#sheets ⇒ Object
Returns an array with the names of the sheets. In Csv class there is only one dummy sheet, because a csv file cannot have more than one sheet.
26 27 28 |
# File 'lib/roo/csv.rb', line 26 def sheets ['default'] end |