Class: CTA::Route
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- CTA::Route
- Defined in:
- lib/cta_redux/models/route.rb
Overview
Current columns: [:route_id, :route_short_name, :route_long_name, :route_type, :route_url, :route_color, :route_text_color]
A Sequel::Model. This corresponds to routes.txt in the GTFS feed, though the CTA does not fully implement the standard.
Defined Under Namespace
Classes: Live
Instance Attribute Summary collapse
Class Method Summary collapse
-
.[](*args) ⇒ CTA::Route
Overrides the default “find by primary key” method in Sequel::Model.
Instance Method Summary collapse
-
#alerts! ⇒ CTA::CustomerAlerts::AlertsResponse
Returns alerts for this route.
-
#locations!(options = {}) ⇒ CTA::TrainTracker::LocationsResponse
Returns the position and next station of all trains in service for this route.
-
#predictions!(options = {}) ⇒ CTA::BusTracker::PredictionsResponse, CTA::TrainTracker::ArrivalsResponse
Returns predictions for this specific Route.
- #route_color ⇒ String (also: #color)
- #route_id ⇒ String (also: #id)
- #route_long_name ⇒ String (also: #long_name)
- #route_short_name ⇒ String (also: #name, #short_name)
- #route_text_color ⇒ String (also: #text_color)
- #route_type ⇒ Integer (also: #type)
- #route_url ⇒ String (also: #url)
-
#status! ⇒ CTA::CustomerAlerts::RouteStatusResponse
Returns an overview of system status for this route.
-
#stops ⇒ Sequel::Dataset
Returns a Sequel::Dataset that corresponds to stops associated with this Route.
-
#trips ⇒ Array<CTA::Trip>
A Route may be associated with multiple trips (“runs”).
Instance Attribute Details
#live ⇒ Live
a CTA::Route will only contain live data when augmented with an API::Response
Returns the Live data associated with this CTA::Route, if available.
9 10 11 |
# File 'lib/cta_redux/models/route.rb', line 9 def live @live end |
Class Method Details
.[](*args) ⇒ CTA::Route
Overrides the default “find by primary key” method in Sequel::Model. Allows you to specify a human-friendly Train name. If you supply something that doesn’t look like an “L” route, it’s passed to the default [] method on Sequel::Model.
48 49 50 51 52 53 54 55 |
# File 'lib/cta_redux/models/route.rb', line 48 def self.[](*args) potential_route = args.first.downcase.to_sym if CTA::Train::FRIENDLY_L_ROUTES.has_key?(potential_route) super(Array.wrap(CTA::Train::FRIENDLY_L_ROUTES[potential_route].capitalize)) else super(args) end end |
Instance Method Details
#alerts! ⇒ CTA::CustomerAlerts::AlertsResponse
Returns alerts for this route
111 112 113 |
# File 'lib/cta_redux/models/route.rb', line 111 def alerts! CTA::CustomerAlerts.alerts!(:routes => self.route_id).alerts end |
#locations!(options = {}) ⇒ CTA::TrainTracker::LocationsResponse
Raises an exception when called on a Bus route, because the BusTracker API has nothing like the TrainTracker locations call
Returns the position and next station of all trains in service for this route.
95 96 97 98 99 100 101 |
# File 'lib/cta_redux/models/route.rb', line 95 def locations!( = {}) if CTA::Train::L_ROUTES.keys.include?(self.route_id.downcase) CTA::TrainTracker.locations!(.merge({:routes => self.route_id.downcase})) else raise "CTA BusTracker has no direct analog of the TrainTracker locations api. Try predictions instead." end end |
#predictions!(options = {}) ⇒ CTA::BusTracker::PredictionsResponse, CTA::TrainTracker::ArrivalsResponse
Returns predictions for this specific CTA::Route. Accepts all optiosn of either BusTracker.predictions! or TrainTracker.predictions!, depending on the type of this CTA::Route
79 80 81 82 83 84 85 |
# File 'lib/cta_redux/models/route.rb', line 79 def predictions!( = {}) if CTA::Train::L_ROUTES.keys.include?(self.route_id.downcase) CTA::TrainTracker.predictions!(.merge({:route => self.route_id.downcase})) else CTA::BusTracker.predictions!(.merge({:route => self.route_id})) end end |
#route_color ⇒ String Also known as: color
31 |
# File 'lib/cta_redux/models/route.rb', line 31 alias_method :id, :route_id |
#route_id ⇒ String Also known as: id
31 |
# File 'lib/cta_redux/models/route.rb', line 31 alias_method :id, :route_id |
#route_long_name ⇒ String Also known as: long_name
31 |
# File 'lib/cta_redux/models/route.rb', line 31 alias_method :id, :route_id |
#route_short_name ⇒ String Also known as: name, short_name
31 |
# File 'lib/cta_redux/models/route.rb', line 31 alias_method :id, :route_id |
#route_text_color ⇒ String Also known as: text_color
31 |
# File 'lib/cta_redux/models/route.rb', line 31 alias_method :id, :route_id |
#route_type ⇒ Integer Also known as: type
31 |
# File 'lib/cta_redux/models/route.rb', line 31 alias_method :id, :route_id |
#route_url ⇒ String Also known as: url
31 |
# File 'lib/cta_redux/models/route.rb', line 31 alias_method :id, :route_id |
#status! ⇒ CTA::CustomerAlerts::RouteStatusResponse
Returns an overview of system status for this route
105 106 107 |
# File 'lib/cta_redux/models/route.rb', line 105 def status! CTA::CustomerAlerts.status!(:routes => self.route_id).routes.first end |
#stops ⇒ Sequel::Dataset
Returns a Sequel::Dataset that corresponds to stops associated with this CTA::Route
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/cta_redux/models/route.rb', line 63 def stops CTA::Stop.with_sql(<<-SQL) SELECT s.* FROM stops s WHERE s.stop_id IN ( SELECT DISTINCT st.stop_id FROM stop_times st JOIN trips t ON st.trip_id = t.trip_id WHERE t.route_id = '#{self.route_id}' ) SQL end |
#trips ⇒ Array<CTA::Trip>
A CTA::Route may be associated with multiple trips (“runs”).
15 |
# File 'lib/cta_redux/models/route.rb', line 15 one_to_many :trips, :key => :route_id |