Class: Samovar::Table
- Inherits:
-
Object
- Object
- Samovar::Table
- Defined in:
- lib/samovar/table.rb
Instance Attribute Summary collapse
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
- #<<(row) ⇒ Object
-
#initialize ⇒ Table
constructor
A new instance of Table.
- #parse(input, command) ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize ⇒ Table
Returns a new instance of Table.
23 24 25 26 |
# File 'lib/samovar/table.rb', line 23 def initialize @rows = [] @parser = [] end |
Instance Attribute Details
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
28 29 30 |
# File 'lib/samovar/table.rb', line 28 def rows @rows end |
Instance Method Details
#<<(row) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/samovar/table.rb', line 30 def << row @rows << row if row.respond_to?(:parse) @parser << row end end |
#parse(input, command) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/samovar/table.rb', line 42 def parse(input, command) @parser.each do |row| current = command.send(row.key) if result = row.parse(input, current) command.send("#{row.key}=", result) end end end |
#usage ⇒ Object
38 39 40 |
# File 'lib/samovar/table.rb', line 38 def usage @rows.collect(&:to_s).join(' ') end |