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::TEMP_PREFIX

Instance Attribute Summary collapse

Attributes inherited from Base

#default_sheet, #header_line, #headers

Instance Method Summary collapse

Methods inherited from Base

#column, #each, #each_with_pagename, #empty?, #find, #first_column, #first_column_as_letter, #first_row, #info, #last_column, #last_column_as_letter, #last_row, #method_missing, #parse, #reload, #row, #row_with, #set, #sheet, #to_csv, #to_matrix, #to_xml, #to_yaml

Constructor Details

#initialize(filename, options = {}) ⇒ CSV

Returns a new instance of CSV.



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

def initialize(filename, options = {})
  super
end

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.



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

def filename
  @filename
end

Instance Method Details

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



27
28
29
30
31
# File 'lib/roo/csv.rb', line 27

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

#cell_postprocessing(row, col, value) ⇒ Object



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

def cell_postprocessing(row,col,value)
  value
end

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



33
34
35
36
37
# File 'lib/roo/csv.rb', line 33

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

#csv_optionsObject



43
44
45
# File 'lib/roo/csv.rb', line 43

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.



23
24
25
# File 'lib/roo/csv.rb', line 23

def sheets
  ['default']
end