Class: OMGCSV::Data

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/omgcsv.rb

Overview

Holds the CSV data and provides useful access

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = [[]]) ⇒ Data

Returns a new instance of Data.



38
39
40
41
42
43
# File 'lib/omgcsv.rb', line 38

def initialize(data=[[]])
  @columns = data[0]
  @rows = data[1..-1].collect do |row|
    GlorifiedHash.new(@columns, row)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/omgcsv.rb', line 49

def method_missing(name, *args)
  if (@rows.respond_to? name)
    @rows.send(name, *args)
  else
    super(name, *args)
  end
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



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

def columns
  @columns
end

#rowsObject (readonly)

Returns the value of attribute rows.



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

def rows
  @rows
end

Instance Method Details

#each(&block) ⇒ Object



45
46
47
# File 'lib/omgcsv.rb', line 45

def each(&block)
  @rows.each(&block)
end