Class: KVVLiveAPI::Departure

Inherits:
Object
  • Object
show all
Defined in:
lib/kvvliveapi/depature.rb

Overview

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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(route, destination, direction, time, lowfloor, realtime, traction, stop_position) ⇒ Departure

Returns a new instance of Departure.



48
49
50
51
52
53
54
55
56
57
# 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

Instance Attribute Details

#destinationObject (readonly)

Final destination of the vehicle



26
27
28
# File 'lib/kvvliveapi/depature.rb', line 26

def destination
  @destination
end

#directionObject (readonly)

Number representing the direction



29
30
31
# File 'lib/kvvliveapi/depature.rb', line 29

def direction
  @direction
end

#lowfloorObject (readonly)

Indicates the accessibility of the used vehicle



32
33
34
# File 'lib/kvvliveapi/depature.rb', line 32

def lowfloor
  @lowfloor
end

#realtimeObject (readonly)

Indicates if the depature is a realtime estimation



35
36
37
# File 'lib/kvvliveapi/depature.rb', line 35

def realtime
  @realtime
end

#routeObject (readonly)

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



23
24
25
# File 'lib/kvvliveapi/depature.rb', line 23

def route
  @route
end

#stop_positionObject (readonly)

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



46
47
48
# File 'lib/kvvliveapi/depature.rb', line 46

def stop_position
  @stop_position
end

#timeObject (readonly)

Depature time



41
42
43
# File 'lib/kvvliveapi/depature.rb', line 41

def time
  @time
end

#tractionObject (readonly)

Specified if single or double traction is used



38
39
40
# File 'lib/kvvliveapi/depature.rb', line 38

def traction
  @traction
end

Class Method Details

.from_json(json) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# 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

Instance Method Details

#to_sObject



59
60
61
# File 'lib/kvvliveapi/depature.rb', line 59

def to_s
  @route + ' (-> ' + @destination + ') @ ' + @time.getlocal.strftime('%H:%M') + ', Stop ' + @stop_position.to_s
end