Class: CycleHire::JourneyParser
- Inherits:
-
Object
- Object
- CycleHire::JourneyParser
- Defined in:
- lib/cycle_hire/journey_parser.rb
Instance Method Summary collapse
-
#initialize(data) ⇒ JourneyParser
constructor
A new instance of JourneyParser.
- #parse ⇒ Object
Constructor Details
#initialize(data) ⇒ JourneyParser
Returns a new instance of JourneyParser.
6 7 8 |
# File 'lib/cycle_hire/journey_parser.rb', line 6 def initialize(data) @data = data end |
Instance Method Details
#parse ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cycle_hire/journey_parser.rb', line 10 def parse rows = rows_from_data(@data) rows.collect do |row| columns = column_data_for_row(row) # ignore the header and other column types if columns[4] == 'Hire' start_time = parse_time(columns[0]) start_station = CycleHire::Station.new(columns[2]) end_time = parse_time(columns[1]) end_station = CycleHire::Station.new(columns[3]) cost = parse_cost(columns[5]) CycleHire::Journey.new(start_time, start_station, end_time, end_station, cost) else nil end end.compact end |