Class: CTA::Stop
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- CTA::Stop
- Defined in:
- lib/cta_redux/models/stop.rb
Overview
Current columns: [:stop_id, :stop_code, :stop_name, :stop_desc, :stop_lat, :stop_lon, :location_type, :parent_station, :wheelchair_boarding]
A Sequel::Model. This corresponds to stops.txt in the GTFS feed, though the CTA does not fully implement the standard.
Class Method Summary collapse
-
.new_from_api_response(s) ⇒ Object
Internal method.
Instance Method Summary collapse
-
#child_stops ⇒ Array<CTA::Stop>
Stops can have a hierarchical relationship.
- #location_type ⇒ Integer
- #parent_station ⇒ Integer
-
#parent_stop ⇒ CTA::Stop
Stops can have a hierarchical relationship.
-
#predictions!(options = {}) ⇒ CTA::BusTracker::PredictionsResponse, CTA::TrainTracker::ArrivalsResponse
Returns predictions for this Stop.
-
#routes ⇒ Sequel::Dataset
Returns a Sequel::Dataset that corresponds to all routes associated with this Stop at some point.
- #stop_code ⇒ Integer (also: #code)
- #stop_desc ⇒ String (also: #description)
- #stop_id ⇒ Integer (also: #id)
- #stop_lat ⇒ Float (also: #lat)
- #stop_lon ⇒ Float (also: #lon)
- #stop_name ⇒ String (also: #name)
-
#stop_type ⇒ :bus, ...
The type of this stop.
-
#transfers_from ⇒ Array<CTA::Stop>
GTFS defines a Transfer object, that describes where customers may transfer lines.
-
#transfers_to ⇒ Array<CTA::Stop>
GTFS defines a Transfer object, that describes where customers may transfer lines.
- #trips ⇒ Array<CTA::Trip>
- #wheelchair_boarding ⇒ true, false
Class Method Details
.new_from_api_response(s) ⇒ Object
Internal method. Some CTA routes are seasonal, and are missing from the GTFS feed. However, the API still returns that info. So, we create a dummy CTA::Stop to fill in the gaps. I’ve emailed CTA developer support for clarification.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/cta_redux/models/stop.rb', line 86 def self.new_from_api_response(s) CTA::Stop.unrestrict_primary_key stop = CTA::Stop.new({ :stop_id => s["stpid"].to_i, :stop_name => s["stpnm"], :stop_lat => s["lat"].to_f, :stop_lon => s["lon"].to_f, :location_type => 3, # Bus in GTFS-land :stop_desc => "#{s["stpnm"]} (seasonal, generated from API results - missing from GTFS feed)" }) CTA::Stop.restrict_primary_key stop end |
Instance Method Details
#child_stops ⇒ Array<CTA::Stop>
Stops can have a hierarchical relationship. The CTA designates certain stops as “parent stops” which contain “child stops” A great example of this is an ‘L’ station - the station itself will be a parent stop, but each platform will be a child stop.
13 |
# File 'lib/cta_redux/models/stop.rb', line 13 one_to_many :child_stops, :class => self, :key => :parent_station |
#location_type ⇒ Integer
56 |
# File 'lib/cta_redux/models/stop.rb', line 56 alias_method :id, :stop_id |
#parent_station ⇒ Integer
56 |
# File 'lib/cta_redux/models/stop.rb', line 56 alias_method :id, :stop_id |
#parent_stop ⇒ CTA::Stop
Stops can have a hierarchical relationship. The CTA designates certain stops as “parent stops” which contain “child stops” A great example of this is an ‘L’ station - the station itself will be a parent stop, but each platform will be a child stop.
18 |
# File 'lib/cta_redux/models/stop.rb', line 18 many_to_one :parent_stop, :class => self, :key => :parent_station |
#predictions!(options = {}) ⇒ CTA::BusTracker::PredictionsResponse, CTA::TrainTracker::ArrivalsResponse
Returns predictions for this CTA::Stop. Accepts all options for BusTracker.predictions! or TrainTracker.predictions!, and will merge in # it’s own stop/station/parent_station ID as needed.
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/cta_redux/models/stop.rb', line 122 def predictions!( = {}) if self.stop_type == :bus CTA::BusTracker.predictions!(.merge({:stops => self.stop_id})) else if self.stop_type == :rail CTA::TrainTracker.predictions!(.merge({:station => self.stop_id})) else CTA::TrainTracker.predictions!(.merge({:parent_station => self.stop_id})) end end end |
#routes ⇒ Sequel::Dataset
Returns a Sequel::Dataset that corresponds to all routes associated with this CTA::Stop at some point
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/cta_redux/models/stop.rb', line 69 def routes CTA::Route.with_sql(<<-SQL) SELECT r.* FROM routes r WHERE r.route_id IN ( SELECT DISTINCT t.route_id FROM stop_times st JOIN trips t ON st.trip_id = t.trip_id WHERE st.stop_id = '#{self.stop_id}' ) SQL end |
#stop_code ⇒ Integer Also known as: code
56 |
# File 'lib/cta_redux/models/stop.rb', line 56 alias_method :id, :stop_id |
#stop_desc ⇒ String Also known as: description
56 |
# File 'lib/cta_redux/models/stop.rb', line 56 alias_method :id, :stop_id |
#stop_id ⇒ Integer Also known as: id
56 |
# File 'lib/cta_redux/models/stop.rb', line 56 alias_method :id, :stop_id |
#stop_lat ⇒ Float Also known as: lat
56 |
# File 'lib/cta_redux/models/stop.rb', line 56 alias_method :id, :stop_id |
#stop_lon ⇒ Float Also known as: lon
56 |
# File 'lib/cta_redux/models/stop.rb', line 56 alias_method :id, :stop_id |
#stop_name ⇒ String Also known as: name
56 |
# File 'lib/cta_redux/models/stop.rb', line 56 alias_method :id, :stop_id |
#stop_type ⇒ :bus, ...
The type of this stop. CTA partitions all stops on the numeric stop_id. It’s unclear why the CTA does this, but the TrainTracker API seems to separate out parent stations and stations in their requests, which complicates following the GTFS spec to the letter. Additionally, because GTFS has no concept of differentiating stops based on the type of vehicle expected to service that stop, the numerical ID can also differentiate a bus stop from a rail stop. Bottom line? The CTA’s APIs and GTFS itself is really confusing, and the actual reasons why this method exists are unclear. You should just be able to rely on it.
108 109 110 111 112 113 114 115 116 |
# File 'lib/cta_redux/models/stop.rb', line 108 def stop_type if self.stop_id < 30000 :bus elsif self.stop_id < 40000 :rail else :parent_station end end |
#transfers_from ⇒ Array<CTA::Stop>
25 |
# File 'lib/cta_redux/models/stop.rb', line 25 one_to_many :transfers_from, :class => 'CTA::Transfer', :key => :from_stop_id |
#transfers_to ⇒ Array<CTA::Stop>
31 |
# File 'lib/cta_redux/models/stop.rb', line 31 one_to_many :transfers_to, :class => 'CTA::Transfer', :key => :to_stop_id |
#trips ⇒ Array<CTA::Trip>
A Route may be related to many trips, through CTA::StopTime objects
36 |
# File 'lib/cta_redux/models/stop.rb', line 36 many_to_many :trips, :left_key => :stop_id, :right_key => :trip_id, :join_table => :stop_times |
#wheelchair_boarding ⇒ true, false
56 |
# File 'lib/cta_redux/models/stop.rb', line 56 alias_method :id, :stop_id |