Class: CycleHire::StationParser
- Inherits:
-
Object
- Object
- CycleHire::StationParser
- Defined in:
- lib/cycle_hire/station_parser.rb
Constant Summary collapse
- STATION_REGEX =
/\{id:"(\d+)".+?name:"(.+?)".+?lat:"(.+?)".+?long:"(.+?)".+?nbBikes:"(\d+)".+?nbEmptyDocks:"(\d+)".+?installed:"(.+?)".+?locked:"(.+?)".+?temporary:"(.+?)"\}/
- TIME_REGEX =
/var hour='(\d\d:\d\d)'/
- ENDPOINT =
"https://web.barclayscyclehire.tfl.gov.uk/maps"
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data) ⇒ StationParser
constructor
A new instance of StationParser.
- #parse ⇒ Object
- #timestamp ⇒ Object
Constructor Details
#initialize(data) ⇒ StationParser
Returns a new instance of StationParser.
14 15 16 |
# File 'lib/cycle_hire/station_parser.rb', line 14 def initialize(data) @data = data end |
Class Method Details
.get_stations ⇒ Object
8 9 10 11 12 |
# File 'lib/cycle_hire/station_parser.rb', line 8 def self.get_stations data = open(ENDPOINT).read parser = self.new data parser.parse end |
Instance Method Details
#parse ⇒ Object
18 19 20 21 22 |
# File 'lib/cycle_hire/station_parser.rb', line 18 def parse @data.scan(STATION_REGEX).map do |station| parse_station(station) end end |
#timestamp ⇒ Object
24 25 26 |
# File 'lib/cycle_hire/station_parser.rb', line 24 def @timestamp ||= Time.parse(TIME_REGEX.match(@data).to_s) end |