Class: CsvReader::Parser
- Inherits:
-
Object
- Object
- CsvReader::Parser
- Defined in:
- lib/csv_reader/parser.rb
Instance Method Summary collapse
- #data_rows ⇒ Object
- #headers ⇒ Object
-
#initialize(csv_data) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
- #rows ⇒ Object
Constructor Details
#initialize(csv_data) ⇒ Parser
Returns a new instance of Parser.
3 4 5 6 |
# File 'lib/csv_reader/parser.rb', line 3 def initialize(csv_data) @csv_data = csv_data parse end |
Instance Method Details
#data_rows ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/csv_reader/parser.rb', line 20 def data_rows rows = [] 1.upto(@rows.length-1).each do |i| rows << @rows[i].split(",").map{|x| x.split.first} end rows end |
#headers ⇒ Object
16 17 18 |
# File 'lib/csv_reader/parser.rb', line 16 def headers @rows[0].split(",").map{|x| x.split.first} end |
#parse ⇒ Object
8 9 10 |
# File 'lib/csv_reader/parser.rb', line 8 def parse @rows = @csv_data.split("\n").reject{|x| x.split == []} end |
#rows ⇒ Object
12 13 14 |
# File 'lib/csv_reader/parser.rb', line 12 def rows @rows end |