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) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/samovar/table.rb', line 48

def parse(input)
	@parser.each do |row|
		if result = row.parse(input)
			yield row.key, result, row
		end
	end
end

#usageObject



38
39
40
41
42
43
44
45
46
# File 'lib/samovar/table.rb', line 38

def usage
	items = Array.new
	
	@rows.each do |row|
		items << row.to_s
	end
	
	items.join(' ')
end