Class: CTA::Route

Inherits:
Sequel::Model
  • Object
show all
Defined in:
lib/cta_redux/models/route.rb

Overview

Note:

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

Instance Method Summary collapse

Instance Attribute Details

#liveLive

Note:

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.

Returns:



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.

Examples:

CTA::Route[:brown] #=> equivalent to calling CTA::Route["Brn"]
CTA::Route["Brown"] #=> equivalent to calling CTA::Route["Brn"]
CTA::Route["8"] #=> equivalent to calling CTA::Route["8"]

Returns:



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

Note:

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.

Examples:

locations!(:route => [:red, :blue])

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :routes (Array<String>, Array<Integer>, String, Integer)

    Routes for which to return positions

Returns:

  • (CTA::TrainTracker::LocationsResponse)


95
96
97
98
99
100
101
# File 'lib/cta_redux/models/route.rb', line 95

def locations!(options = {})
  if CTA::Train::L_ROUTES.keys.include?(self.route_id.downcase)
    CTA::TrainTracker.locations!(options.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!(options = {})
  if CTA::Train::L_ROUTES.keys.include?(self.route_id.downcase)
    CTA::TrainTracker.predictions!(options.merge({:route => self.route_id.downcase}))
  else
    CTA::BusTracker.predictions!(options.merge({:route => self.route_id}))
  end
end

#route_colorString Also known as: color

Returns:

  • (String)


31
# File 'lib/cta_redux/models/route.rb', line 31

alias_method :id, :route_id

#route_idString Also known as: id

Returns:

  • (String)


31
# File 'lib/cta_redux/models/route.rb', line 31

alias_method :id, :route_id

#route_long_nameString Also known as: long_name

Returns:

  • (String)


31
# File 'lib/cta_redux/models/route.rb', line 31

alias_method :id, :route_id

#route_short_nameString Also known as: name, short_name

Returns:

  • (String)


31
# File 'lib/cta_redux/models/route.rb', line 31

alias_method :id, :route_id

#route_text_colorString Also known as: text_color

Returns:

  • (String)


31
# File 'lib/cta_redux/models/route.rb', line 31

alias_method :id, :route_id

#route_typeInteger Also known as: type

Returns:

  • (Integer)


31
# File 'lib/cta_redux/models/route.rb', line 31

alias_method :id, :route_id

#route_urlString Also known as: url

Returns:

  • (String)


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

#stopsSequel::Dataset

Returns a Sequel::Dataset that corresponds to stops associated with this CTA::Route

Examples:

CTA::Route["brown"].stops.first #=> #<CTA::Stop...
CTA::Route["brown"].stops.all   #=> [#<CTA::Stop..., #<CTA::Stop...]

Returns:

  • (Sequel::Dataset)


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

#tripsArray<CTA::Trip>

A CTA::Route may be associated with multiple trips (“runs”).

Returns:



15
# File 'lib/cta_redux/models/route.rb', line 15

one_to_many :trips, :key => :route_id