Class: Onebusaway::ArrivalAndDeparture

Inherits:
Base
  • Object
show all
Defined in:
lib/onebusaway.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

from_xml

Instance Attribute Details

#predictedArrivalTimeObject

Returns the value of attribute predictedArrivalTime.



124
125
126
# File 'lib/onebusaway.rb', line 124

def predictedArrivalTime
  @predictedArrivalTime
end

#predictedDepartureTimeObject

Returns the value of attribute predictedDepartureTime.



124
125
126
# File 'lib/onebusaway.rb', line 124

def predictedDepartureTime
  @predictedDepartureTime
end

#routeIdObject

Returns the value of attribute routeId.



124
125
126
# File 'lib/onebusaway.rb', line 124

def routeId
  @routeId
end

#routeShortNameObject

Returns the value of attribute routeShortName.



124
125
126
# File 'lib/onebusaway.rb', line 124

def routeShortName
  @routeShortName
end

#scheduledArrivalTimeObject

Returns the value of attribute scheduledArrivalTime.



124
125
126
# File 'lib/onebusaway.rb', line 124

def scheduledArrivalTime
  @scheduledArrivalTime
end

#scheduledDepartureTimeObject

Returns the value of attribute scheduledDepartureTime.



124
125
126
# File 'lib/onebusaway.rb', line 124

def scheduledDepartureTime
  @scheduledDepartureTime
end

#statusObject

Returns the value of attribute status.



124
125
126
# File 'lib/onebusaway.rb', line 124

def status
  @status
end

#stopIdObject

Returns the value of attribute stopId.



124
125
126
# File 'lib/onebusaway.rb', line 124

def stopId
  @stopId
end

#tripHeadsignObject

Returns the value of attribute tripHeadsign.



124
125
126
# File 'lib/onebusaway.rb', line 124

def tripHeadsign
  @tripHeadsign
end

#tripIdObject

Returns the value of attribute tripId.



124
125
126
# File 'lib/onebusaway.rb', line 124

def tripId
  @tripId
end

Class Method Details

.parse(data) ⇒ Object



125
126
127
128
129
130
131
132
# File 'lib/onebusaway.rb', line 125

def self.parse(data)
  arrival = self.new
  [:routeId, :routeShortName, :tripId, :tripHeadsign, :stopId, :predictedArrivalTime, :scheduledArrivalTime, :predictedDepartureTime, :scheduledDepartureTime, :status].each do |attr|
    value = data.elements[attr.to_s]
    arrival.send("#{attr}=", value.text) if value
  end
  arrival
end

Instance Method Details

#minutes_from_nowObject



134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/onebusaway.rb', line 134

def minutes_from_now
  @minutes_from_now ||= begin
    at = predictedArrivalTime.to_i
    if at == 0
      # no predicted time, use scheduled
      (scheduledArrivalTime.to_i/1000 - Time.now.to_i) / 60
    else
      (predictedArrivalTime.to_i/1000 - Time.now.to_i) / 60
    end
  end
  @minutes_from_now
end