Class: CitibikeTrips::Stations

Inherits:
Object
  • Object
show all
Defined in:
lib/citibike_trips/stations.rb

Constant Summary collapse

STATIONS_URL =
'https://www.citibikenyc.com/stations/json'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStations

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)
  @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

#stationsObject (readonly)

Returns the value of attribute stations.



4
5
6
# File 'lib/citibike_trips/stations.rb', line 4

def stations
  @stations
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



4
5
6
# File 'lib/citibike_trips/stations.rb', line 4

def timestamp
  @timestamp
end

Instance Method Details

#[](id) ⇒ Object



18
19
20
# File 'lib/citibike_trips/stations.rb', line 18

def [](id)
  @stations[id]
end