Class: CTA::Bus::Live

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(position, predictions = []) ⇒ Live

Returns a new instance of Live.



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

def initialize(position, predictions = [])
  @lat = position["lat"].to_f
  @lon = position["lon"].to_f
  @heading = position["hdg"].to_i
  @vehicle_id = position["vid"].to_i
  @pattern_id = position["pid"].to_i
  @pattern_distance = position["pdist"].to_i
  @route = CTA::Route.where(:route_id => position["rt"]).first
  @delayed = (position["dly"] == "true")
  @speed = position["spd"].to_i

  @predictions = Array.wrap(predictions).map { |p| Prediction.new(p) }
end

Instance Attribute Details

#delayedtrue, false (readonly)

Returns True if the CTA::Bus is considered to be delayed.

Returns:

  • (true, false)

    True if the CTA::Bus is considered to be delayed.



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

def delayed
  @delayed
end

#headingInteger (readonly)

Returns The heading of the CTA::Bus.

Returns:

  • (Integer)

    The heading of the CTA::Bus.



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

def heading
  @heading
end

#latFloat (readonly)

Returns The latitude of the CTA::Bus.

Returns:

  • (Float)

    The latitude of the CTA::Bus.



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

def lat
  @lat
end

#lonFloat (readonly)

Returns The longitude of the CTA::Bus.

Returns:

  • (Float)

    The longitude of the CTA::Bus.



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

def lon
  @lon
end

#pattern_distanceInteger (readonly)

Returns The distance into the pattern the CTA::Bus is following.

Returns:

  • (Integer)

    The distance into the pattern the CTA::Bus is following.



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

def pattern_distance
  @pattern_distance
end

#pattern_idInteger (readonly)

Returns The pattern the CTA::Bus is following.

Returns:

  • (Integer)

    The pattern the CTA::Bus is following.



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

def pattern_id
  @pattern_id
end

#predictionsArray<Prediction> (readonly)

Returns Predictions for this CTA::Bus.

Returns:



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

def predictions
  @predictions
end

#routeCTA::Route (readonly)

Returns The Route the CTA::Bus is operating.

Returns:



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

def route
  @route
end

#speedInteger (readonly)

Returns Last reported speed of the CTA::Bus, in mph.

Returns:

  • (Integer)

    Last reported speed of the CTA::Bus, in mph.



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

def speed
  @speed
end

#vehicle_idInteger (readonly)

Returns The vehicle_id of the CTA::Bus.

Returns:

  • (Integer)

    The vehicle_id of the CTA::Bus.



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

def vehicle_id
  @vehicle_id
end