Class: Haecksler::Row
- Inherits:
-
Object
- Object
- Haecksler::Row
- Defined in:
- lib/haecksler/row.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
Instance Method Summary collapse
- #<<(column) ⇒ Object
- #[](key) ⇒ Object
- #footer? ⇒ Boolean
- #header? ⇒ Boolean
-
#initialize(columns = []) ⇒ Row
constructor
A new instance of Row.
- #parse(input) ⇒ Object
Constructor Details
#initialize(columns = []) ⇒ Row
Returns a new instance of Row.
6 7 8 |
# File 'lib/haecksler/row.rb', line 6 def initialize(columns = []) @columns = columns end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
4 5 6 |
# File 'lib/haecksler/row.rb', line 4 def columns @columns end |
Instance Method Details
#<<(column) ⇒ Object
10 11 12 |
# File 'lib/haecksler/row.rb', line 10 def <<(column) @columns << column end |
#[](key) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/haecksler/row.rb', line 14 def [](key) begin @columns.find{|c| c.name == key }.value rescue nil end end |
#footer? ⇒ Boolean
45 46 47 |
# File 'lib/haecksler/row.rb', line 45 def false end |
#header? ⇒ Boolean
41 42 43 |
# File 'lib/haecksler/row.rb', line 41 def header? false end |
#parse(input) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/haecksler/row.rb', line 22 def parse(input) indizes = columns.map(&:size).reduce([0]) do |memo,item| memo << (memo.last.to_i + item) memo end slices = input.split(//).each_with_index.slice_before { | element | indizes.include? element[1] } parsed_columns = slices.map {|slice| slice.map{|i| i[0]}.join("")}.zip(columns).map do |text, column| column.parse(text) end @columns = parsed_columns self end |