Class: Emmental
- Inherits:
-
Object
- Object
- Emmental
- Includes:
- Enumerable
- Defined in:
- lib/emmental.rb,
lib/emmental/row.rb,
lib/emmental/headers.rb,
lib/emmental/version.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
- #add_row(hash) ⇒ Object (also: #<<)
- #each ⇒ Object
-
#initialize(headers = []) ⇒ Emmental
constructor
A new instance of Emmental.
- #to_a(options = {}) ⇒ Object
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
#headers ⇒ Object
Returns the value of attribute headers.
8 9 10 |
# File 'lib/emmental.rb', line 8 def headers @headers end |
#rows ⇒ Object (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 |
#each ⇒ Object
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(={}) array = ([:headers] == false) ? [] : [@headers] @rows.each do |row| array << @headers.map{|header| row.to_h[header] } end array end |