Class: Translink::Page::Trip
- Inherits:
-
Translink::Page
- Object
- Translink::Page
- Translink::Page::Trip
- Defined in:
- lib/translink/page/trip.rb
Defined Under Namespace
Constant Summary
Constants inherited from Translink::Page
Instance Attribute Summary collapse
-
#date ⇒ Object
- Date
-
Date the trip runs on.
-
#direction ⇒ Object
Returns the value of attribute direction.
Attributes inherited from Translink::Page
Instance Method Summary collapse
-
#headsign ⇒ String
Get the trip’s headsign.
-
#initialize(url, date, direction) ⇒ Trip
constructor
Creates a new trip.
-
#stop_times ⇒ Array<Page::Trip::StopTime>
Builds an unique array of stop times.
-
#trip_id ⇒ String
Get the trip’s unique ID.
Constructor Details
#initialize(url, date, direction) ⇒ Trip
Creates a new trip.
65 66 67 68 69 |
# File 'lib/translink/page/trip.rb', line 65 def initialize url, date, direction super url @date = date.to_date @direction = direction end |
Instance Attribute Details
#date ⇒ Object
- Date
-
Date the trip runs on.
57 58 59 |
# File 'lib/translink/page/trip.rb', line 57 def date @date end |
#direction ⇒ Object
Returns the value of attribute direction.
58 59 60 |
# File 'lib/translink/page/trip.rb', line 58 def direction @direction end |
Instance Method Details
#headsign ⇒ String
Get the trip’s headsign.
74 75 76 77 |
# File 'lib/translink/page/trip.rb', line 74 def headsign url.to_s =~ /information\/([a-z]+)\// $1 end |
#stop_times ⇒ Array<Page::Trip::StopTime>
Builds an unique array of stop times.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/translink/page/trip.rb', line 90 def stop_times page.search('table#trip-details tbody tr').reduce(Array.new) do |stop_times, table_row| stop_time = StopTime.new.html! table_row duplicate = stop_times.find do |duplicate| duplicate.stop_page.stop_id == stop_time.stop_page.stop_id && duplicate.arrival_time == stop_time.arrival_time end stop_times << stop_time unless duplicate stop_times end.each_with_index.map do |stop_time, index| stop_time.stop_sequence = index stop_time end end |
#trip_id ⇒ String
Get the trip’s unique ID.
82 83 84 85 |
# File 'lib/translink/page/trip.rb', line 82 def trip_id url.to_s =~ /information\/[a-z]+\/[^\/]+\/([^\/]+)/ $1 end |