Class: Samovar::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/samovar/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTable

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

#rowsObject (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

#usageObject



38
39
40
# File 'lib/samovar/table.rb', line 38

def usage
  @rows.collect(&:to_s).join(' ')
end