Class: CitibikeTrips::Stations
- Inherits:
-
Object
- Object
- CitibikeTrips::Stations
- Defined in:
- lib/citibike_trips/stations.rb
Constant Summary collapse
- STATIONS_URL =
'https://www.citibikenyc.com/stations/json'
Instance Attribute Summary collapse
-
#stations ⇒ Object
readonly
Returns the value of attribute stations.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
- #[](id) ⇒ Object
-
#initialize ⇒ Stations
constructor
A new instance of Stations.
Constructor Details
#initialize ⇒ Stations
Returns a new instance of Stations.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/citibike_trips/stations.rb', line 6 def initialize agent = Mechanize.new page = agent.get(STATIONS_URL) data = JSON.parse(page.body) = Time.parse(data['executionTime']) @stations = {} data['stationBeanList'].each do |s| station = CitibikeTrips::Station.new(s) @stations[station.id] = station end end |
Instance Attribute Details
#stations ⇒ Object (readonly)
Returns the value of attribute stations.
4 5 6 |
# File 'lib/citibike_trips/stations.rb', line 4 def stations @stations end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
4 5 6 |
# File 'lib/citibike_trips/stations.rb', line 4 def end |
Instance Method Details
#[](id) ⇒ Object
18 19 20 |
# File 'lib/citibike_trips/stations.rb', line 18 def [](id) @stations[id] end |