Class: LittleTable
- Inherits:
-
Object
- Object
- LittleTable
- Defined in:
- lib/little_table.rb
Constant Summary collapse
- VERSION =
"1.0.1"
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
7 8 9 |
# File 'lib/little_table.rb', line 7 def initialize input @table_string = input end |
Instance Method Details
#hashes ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/little_table.rb', line 23 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
15 16 17 |
# File 'lib/little_table.rb', line 15 def headers parse_line_number 0 end |
#length ⇒ Object
11 12 13 |
# File 'lib/little_table.rb', line 11 def length @table_string.lines.count - 1 end |
#rows ⇒ Object
19 20 21 |
# File 'lib/little_table.rb', line 19 def rows @table_string.lines[1..-1].map { |line| parse_line line } end |