Class: CTA::Bus::Prediction

Inherits:
Object
  • Object
show all
Defined in:
lib/cta_redux/models/bus.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Prediction

Returns a new instance of Prediction.



110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/cta_redux/models/bus.rb', line 110

def initialize(data)
  @type = data["typ"]
  @stop = CTA::Stop.where(:stop_id => data["stpid"]).first || CTA::Stop.new_from_api_response(data)
  @distance = data["dstp"].to_i
  @route = CTA::Route.where(:route_id => data["rt"]).first
  @direction = CTA::BusTracker::Direction.new(data["rtdir"])
  @headsign = data["des"]
  @prediction_generated_at = DateTime.parse(data["tmstmp"])
  @arrival_time = DateTime.parse(data["prdtm"])
  @seconds = @arrival_time.to_time - @prediction_generated_at.to_time
  @minutes = (@seconds / 60).ceil
  @delayed = (data["dly"] == "true")
end

Instance Attribute Details

#arrival_timeDateTime (readonly)

Returns The time this bus is predicted to arrive or depart.

Returns:

  • (DateTime)

    The time this bus is predicted to arrive or depart



102
103
104
# File 'lib/cta_redux/models/bus.rb', line 102

def arrival_time
  @arrival_time
end

#delayedtrue, false (readonly)

Returns True if this bus is considered to be delayed.

Returns:

  • (true, false)

    True if this bus is considered to be delayed



104
105
106
# File 'lib/cta_redux/models/bus.rb', line 104

def delayed
  @delayed
end

#directionDirection (readonly)

Returns The Direction associated with this prediction.

Returns:

  • (Direction)

    The Direction associated with this prediction



96
97
98
# File 'lib/cta_redux/models/bus.rb', line 96

def direction
  @direction
end

#distanceInteger (readonly)

Returns The distance remaining until the bus arrives.

Returns:

  • (Integer)

    The distance remaining until the bus arrives



92
93
94
# File 'lib/cta_redux/models/bus.rb', line 92

def distance
  @distance
end

#headsignString (readonly)

Returns The headsign of the bus (final destination, not expressed as Stop).

Returns:

  • (String)

    The headsign of the bus (final destination, not expressed as Stop)



98
99
100
# File 'lib/cta_redux/models/bus.rb', line 98

def headsign
  @headsign
end

#minutesInteger (readonly)

Returns The number of minutes until this bus arrives or departs.

Returns:

  • (Integer)

    The number of minutes until this bus arrives or departs



106
107
108
# File 'lib/cta_redux/models/bus.rb', line 106

def minutes
  @minutes
end

#prediction_generated_atDateTime (readonly)

Returns The time this CTA::Bus::Prediction was generated on the BusTime servers.

Returns:



100
101
102
# File 'lib/cta_redux/models/bus.rb', line 100

def prediction_generated_at
  @prediction_generated_at
end

#routeCTA::Route (readonly)

Returns The Route associated with this prediction.

Returns:



94
95
96
# File 'lib/cta_redux/models/bus.rb', line 94

def route
  @route
end

#secondsInteger (readonly)

Returns The number of seconds until this bus arrives or departs.

Returns:

  • (Integer)

    The number of seconds until this bus arrives or departs



108
109
110
# File 'lib/cta_redux/models/bus.rb', line 108

def seconds
  @seconds
end

#stopCTA::Stop (readonly)

Returns The Stop for this prediction.

Returns:



90
91
92
# File 'lib/cta_redux/models/bus.rb', line 90

def stop
  @stop
end

#typeString (readonly)

Returns The type of prediction, either *A*rrival or *D*eparture.

Returns:

  • (String)

    The type of prediction, either *A*rrival or *D*eparture



88
89
90
# File 'lib/cta_redux/models/bus.rb', line 88

def type
  @type
end