Class: CitibikeTrips::Stations
- Inherits:
-
Object
- Object
- CitibikeTrips::Stations
- Includes:
- Enumerable
- 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
- #each(&block) ⇒ Object
-
#initialize ⇒ Stations
constructor
A new instance of Stations.
- #to_json(*a) ⇒ Object
Constructor Details
#initialize ⇒ Stations
Returns a new instance of Stations.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/citibike_trips/stations.rb', line 9 def initialize agent = Mechanize.new page = agent.get(STATIONS_URL) data = JSON.parse(page.body) @timestamp = 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.
7 8 9 |
# File 'lib/citibike_trips/stations.rb', line 7 def stations @stations end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
7 8 9 |
# File 'lib/citibike_trips/stations.rb', line 7 def @timestamp end |
Instance Method Details
#[](id) ⇒ Object
21 22 23 |
# File 'lib/citibike_trips/stations.rb', line 21 def [](id) @stations[id] end |
#each(&block) ⇒ Object
24 25 26 |
# File 'lib/citibike_trips/stations.rb', line 24 def each(&block) @stations.each(&block) end |
#to_json(*a) ⇒ Object
27 28 29 |
# File 'lib/citibike_trips/stations.rb', line 27 def to_json(*a) @stations.to_json(*a) end |