Class: CitibikeTrips::Trips
- Inherits:
-
Object
- Object
- CitibikeTrips::Trips
- Defined in:
- lib/citibike_trips/trips.rb
Constant Summary collapse
- TRIPS_URL =
'https://www.citibikenyc.com/member/trips'
Instance Attribute Summary collapse
-
#trips ⇒ Object
readonly
Returns the value of attribute trips.
Instance Method Summary collapse
-
#initialize ⇒ Trips
constructor
A new instance of Trips.
Constructor Details
#initialize ⇒ Trips
Returns a new instance of Trips.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/citibike_trips/trips.rb', line 6 def initialize agent = Mechanize.new @trips = [] url = TRIPS_URL loop do page = agent.get(url) if page.uri.to_s == url page.search('tr.trip').each do |triprow| trips << CitibikeTrips::Trip.new( triprow.attributes['id'].value, triprow.attributes['data-start-station-id'].value, triprow.attributes['data-end-station-id'].value, triprow.attributes['data-start-timestamp'].value, triprow.attributes['data-end-timestamp'].value) end if nextpagelink = page.link_with(text: '>') url = nextpagelink.href else break end elsif page.uri.to_s == CitibikeTrips::LOGIN_URL CitibikeTrips.login(page) else raise "Got redirected to unexpected page #{page.uri.to_s}" end end end |
Instance Attribute Details
#trips ⇒ Object (readonly)
Returns the value of attribute trips.
4 5 6 |
# File 'lib/citibike_trips/trips.rb', line 4 def trips @trips end |