class KVVLiveAPI::Departure

Instances of this class represent the depature of a vehicle of a specific route with a specified destination at a specified time.

It contins additional information about the depature and vehicle.

Attributes

destination[R]

Final destination of the vehicle

direction[R]

Number representing the direction

lowfloor[R]

Indicates the accessibility of the used vehicle

realtime[R]

Indicates if the depature is a realtime estimation

route[R]

The route for which the depature is valid, e.g. 2 or S7

stop_position[R]

Number representing the “sub-stop”, as in some cases a single stops might have different sub-stops for different kinds if vehicles

time[R]

Depature time

traction[R]

Specified if single or double traction is used

Public Class Methods

from_json(json) click to toggle source
# File lib/kvvliveapi/depature.rb, line 10
def from_json(json)
  new(json['route'],
      json['destination'],
      json['direction'],
      json['time'],
      json['lowfloor'],
      json['realtime'],
      json['traction'],
      json['stopPosition'])
end
new(route, destination, direction, time, lowfloor, realtime, traction, stop_position) click to toggle source
# File lib/kvvliveapi/depature.rb, line 48
def initialize(route, destination, direction, time, lowfloor, realtime, traction, stop_position)
  @route = route
  @destination = destination
  @direction = direction
  @lowfloor = lowfloor
  @realtime = realtime
  @traction = traction
  @time = convert_timestr(time)
  @stop_position = stop_position
end

Public Instance Methods

to_s() click to toggle source
# File lib/kvvliveapi/depature.rb, line 59
def to_s
  @route + ' (-> ' + @destination + ') @ ' + @time.getlocal.strftime('%H:%M') + ', Stop ' + @stop_position.to_s
end

Private Instance Methods

convert_timestr(time) click to toggle source
# File lib/kvvliveapi/depature.rb, line 65
def convert_timestr(time)
  timestr = time.to_s
  now = Time.now.getlocal

  return now.getutc if timestr == 'sofort' || timestr == '0'

  if (mtch = /^([1-9]) min$/.match(timestr))
    return now.advance(minutes: mtch[1].to_i).getutc
  end

  if (mtch = /^([0-2]?[0-9]):([0-5][0-9])$/.match(timestr))
    resulting_time = now.change(hour: mtch[1].to_i, min: mtch[2].to_i)
    resulting_time += 1.day if resulting_time < now
    return resulting_time.getutc
  end

  nil
end