Class: Emmental

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/emmental.rb,
lib/emmental/row.rb,
lib/emmental/headers.rb,
lib/emmental/version.rb

Defined Under Namespace

Classes: Headers, Row

Constant Summary collapse

VERSION =
"0.0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(headers = []) ⇒ Emmental

Returns a new instance of Emmental.



11
12
13
14
# File 'lib/emmental.rb', line 11

def initialize(headers=[])
  @headers = Emmental::Headers.new(headers)
  @rows    = []
end

Instance Attribute Details

#headersObject

Returns the value of attribute headers.



8
9
10
# File 'lib/emmental.rb', line 8

def headers
  @headers
end

#rowsObject (readonly)

Returns the value of attribute rows.



9
10
11
# File 'lib/emmental.rb', line 9

def rows
  @rows
end

Instance Method Details

#add_row(hash) ⇒ Object Also known as: <<



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

def add_row(hash)
  @rows << Emmental::Row.new(hash, @headers)
end

#eachObject



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

def each
  @rows.each{|row| yield(row) }
end

#to_a(options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/emmental.rb', line 25

def to_a(options={})
  array = (options[:headers] == false) ? [] : [@headers]

  @rows.each do |row|
    array << @headers.map{|header| row.to_h[header] }
  end

  array
end