Class: CitibikeTrips::Stations

Inherits:
Object
  • Object
show all
Includes:
Enumerable
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.



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

#stationsObject (readonly)

Returns the value of attribute stations.



7
8
9
# File 'lib/citibike_trips/stations.rb', line 7

def stations
  @stations
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



7
8
9
# File 'lib/citibike_trips/stations.rb', line 7

def timestamp
  @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