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.



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/cta_redux/models/bus.rb', line 71

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.



65
66
67
# File 'lib/cta_redux/models/bus.rb', line 65

def delayed
  @delayed
end

#headingInteger (readonly)

Returns The heading of the CTA::Bus.

Returns:

  • (Integer)

    The heading of the CTA::Bus.



57
58
59
# File 'lib/cta_redux/models/bus.rb', line 57

def heading
  @heading
end

#latFloat (readonly)

Returns The latitude of the CTA::Bus.

Returns:

  • (Float)

    The latitude of the CTA::Bus.



51
52
53
# File 'lib/cta_redux/models/bus.rb', line 51

def lat
  @lat
end

#lonFloat (readonly)

Returns The longitude of the CTA::Bus.

Returns:

  • (Float)

    The longitude of the CTA::Bus.



53
54
55
# File 'lib/cta_redux/models/bus.rb', line 53

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.



61
62
63
# File 'lib/cta_redux/models/bus.rb', line 61

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.



59
60
61
# File 'lib/cta_redux/models/bus.rb', line 59

def pattern_id
  @pattern_id
end

#predictionsArray<Prediction> (readonly)

Returns Predictions for this CTA::Bus.

Returns:



69
70
71
# File 'lib/cta_redux/models/bus.rb', line 69

def predictions
  @predictions
end

#routeCTA::Route (readonly)

Returns The Route the CTA::Bus is operating.

Returns:



63
64
65
# File 'lib/cta_redux/models/bus.rb', line 63

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.



67
68
69
# File 'lib/cta_redux/models/bus.rb', line 67

def speed
  @speed
end

#vehicle_idInteger (readonly)

Returns The vehicle_id of the CTA::Bus.

Returns:

  • (Integer)

    The vehicle_id of the CTA::Bus.



55
56
57
# File 'lib/cta_redux/models/bus.rb', line 55

def vehicle_id
  @vehicle_id
end