Class: Roo::CSV

Inherits:
Base
  • Object
show all
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.

You can pass options to the underlying CSV parse operation, via the :csv_options option.

Constant Summary

Constants inherited from Base

Base::MAX_ROW_COL, Base::MIN_ROW_COL, Base::TEMP_PREFIX

Instance Attribute Summary collapse

Attributes inherited from Base

#header_line, #headers

Instance Method Summary collapse

Methods inherited from Base

#cell_type_by_value, #close, #collect_last_row_col_for_sheet, #column, #default_sheet, #default_sheet=, #each, #each_with_pagename, #empty?, #find, #first_column_as_letter, #first_last_row_col_for_sheet, #info, #initialize, #inspect, #last_column_as_letter, #method_missing, #parse, #reload, #row, #row_with, #set, #sheet, #to_csv, #to_matrix, #to_xml, #to_yaml

Constructor Details

This class inherits a constructor from Roo::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Roo::Base

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



16
17
18
# File 'lib/roo/csv.rb', line 16

def filename
  @filename
end

Instance Method Details

#cell(row, col, sheet = nil) ⇒ Object



24
25
26
27
28
# File 'lib/roo/csv.rb', line 24

def cell(row, col, sheet=nil)
  sheet ||= default_sheet
  read_cells(sheet)
  @cell[normalize(row,col)]
end

#cell_postprocessing(row, col, value) ⇒ Object



36
37
38
# File 'lib/roo/csv.rb', line 36

def cell_postprocessing(row,col,value)
  value
end

#celltype(row, col, sheet = nil) ⇒ Object



30
31
32
33
34
# File 'lib/roo/csv.rb', line 30

def celltype(row, col, sheet=nil)
  sheet ||= default_sheet
  read_cells(sheet)
  @cell_type[normalize(row,col)]
end

#csv_optionsObject



40
41
42
# File 'lib/roo/csv.rb', line 40

def csv_options
  @options[:csv_options] || {}
end

#sheetsObject

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.



20
21
22
# File 'lib/roo/csv.rb', line 20

def sheets
  ['default']
end