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
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.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/roo/csv.rb', line 12 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 Method Details
#cell(row, col, sheet = nil) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/roo/csv.rb', line 29 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
43 44 45 |
# File 'lib/roo/csv.rb', line 43 def cell_postprocessing(row,col,value) value end |
#celltype(row, col, sheet = nil) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/roo/csv.rb', line 36 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.
25 26 27 |
# File 'lib/roo/csv.rb', line 25 def sheets ['default'] end |