Class: CTA::BusTracker::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/cta_redux/api/bus_tracker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s) ⇒ Service

Returns a new instance of Service.



154
155
156
157
158
159
160
161
162
163
# File 'lib/cta_redux/api/bus_tracker.rb', line 154

def initialize(s)
  @route = CTA::Route.where(:route_id => s["rt"]).first
  @direction = Direction.new(s["rtdir"]) if s["rtdir"]
  if s["stpid"]
    @stop = CTA::Stop.where(:stop_id => s["stpid"]).first || CTA::Stop.new_from_api_response(s)
    @stop_name = @stop.name
  else
    @stop_name = s["stpnm"] # ugh
  end
end

Instance Attribute Details

#directionDirection (readonly)

Returns A Direction object for the direction, if any, affected by a CTA::BusTracker::ServiceBulletin.

Returns:



145
146
147
# File 'lib/cta_redux/api/bus_tracker.rb', line 145

def direction
  @direction
end

#routeCTA::Route (readonly)

Returns A Route, if any, affected by a CTA::BusTracker::ServiceBulletin.

Returns:



143
144
145
# File 'lib/cta_redux/api/bus_tracker.rb', line 143

def route
  @route
end

#stopCTA::Stop (readonly)

Returns A specific Stop object for the stop affected by a CTA::BusTracker::ServiceBulletin.

Returns:



147
148
149
# File 'lib/cta_redux/api/bus_tracker.rb', line 147

def stop
  @stop
end

#stop_nameString (readonly)

Note:

Usually this is equivalent to calling stop.name, but sometimes the CTA returns a CTA::BusTracker::ServiceBulletin with a stop name, but no stop id set - and the stop name may not exactly correspond to a Stop object in the GTFS feed.

Returns The name of the Stop affected.

Returns:

  • (String)

    The name of the Stop affected.



152
153
154
# File 'lib/cta_redux/api/bus_tracker.rb', line 152

def stop_name
  @stop_name
end

Instance Method Details

#predictions!Object



165
166
167
168
169
# File 'lib/cta_redux/api/bus_tracker.rb', line 165

def predictions!
  options = { :route => self.route }
  options.merge!({ :stop => self.stop_id }) if self.stop_id
  CTA::BusTracker.predictions!(options)
end