Class: LittleTable
- Inherits:
-
Object
- Object
- LittleTable
- Defined in:
- lib/little_table.rb
Instance Method Summary collapse
- #hashes ⇒ Object
- #headers ⇒ Object
-
#initialize(input) ⇒ LittleTable
constructor
A new instance of LittleTable.
- #length ⇒ Object
- #rows ⇒ Object
Constructor Details
#initialize(input) ⇒ LittleTable
Returns a new instance of LittleTable.
5 6 7 |
# File 'lib/little_table.rb', line 5 def initialize input @table_string = input end |
Instance Method Details
#hashes ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/little_table.rb', line 21 def hashes result = [] rows.each do |row| row_hash = {} headers.each_with_index do |header, index| row_hash[header.parameterize('_').to_sym] = row[index] end result.push row_hash end result end |
#headers ⇒ Object
13 14 15 |
# File 'lib/little_table.rb', line 13 def headers parse_line_number 0 end |
#length ⇒ Object
9 10 11 |
# File 'lib/little_table.rb', line 9 def length @table_string.lines.count - 1 end |
#rows ⇒ Object
17 18 19 |
# File 'lib/little_table.rb', line 17 def rows @table_string.lines[1..-1].map { |line| parse_line line } end |