Class: NationalRail::VirginLiveDepartureBoards::TimeParser
- Inherits:
-
Object
- Object
- NationalRail::VirginLiveDepartureBoards::TimeParser
- Defined in:
- lib/national-rail/virgin_live_departure_boards.rb
Instance Method Summary collapse
-
#initialize(time = Time.zone.now) ⇒ TimeParser
constructor
A new instance of TimeParser.
- #parse(value) ⇒ Object
Constructor Details
#initialize(time = Time.zone.now) ⇒ TimeParser
Returns a new instance of TimeParser.
16 17 18 |
# File 'lib/national-rail/virgin_live_departure_boards.rb', line 16 def initialize(time = Time.zone.now) @time = time end |
Instance Method Details
#parse(value) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/national-rail/virgin_live_departure_boards.rb', line 19 def parse(value) value = value.gsub(%r{&#\d+;}, '').gsub(%r{\*+$}, '') return value if ['On time', 'Starts here', 'No report', 'Cancelled', 'Delayed'].include?(value) parts = value.scan(%r{\d{2}}) return nil unless parts.length == 2 hhmm = parts.join(':') time = Time.zone.parse("#{@time.to_date} #{hhmm}") if time > 12.hours.from_now(@time) time = Time.zone.parse("#{@time.to_date - 1} #{hhmm}") elsif time < 12.hours.ago(@time) time = Time.zone.parse("#{@time.to_date + 1} #{hhmm}") end time end |