Class: StationMaster::Schedule::Departure

Inherits:
Object
  • Object
show all
Defined in:
lib/station_master/schedule/departure.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Departure

Returns a new instance of Departure.



6
7
8
9
10
11
12
13
# File 'lib/station_master/schedule/departure.rb', line 6

def initialize(hash)
  @train_code = hash[:numeroTreno]
  @train_type = hash[:categoria]
  @destination = hash[:destinazione]
  @platform = (hash[:binarioProgrammatoPartenzaDescrizione].to_s || '0').strip
  @time = Time.at((hash[:orarioPartenza] || 0) / 1000).in_time_zone(TIME_ZONE)
  @delay = hash[:ritardo]
end

Instance Attribute Details

#delayObject (readonly)

Returns the value of attribute delay.



4
5
6
# File 'lib/station_master/schedule/departure.rb', line 4

def delay
  @delay
end

#destinationObject (readonly)

Returns the value of attribute destination.



4
5
6
# File 'lib/station_master/schedule/departure.rb', line 4

def destination
  @destination
end

#platformObject (readonly)

Returns the value of attribute platform.



4
5
6
# File 'lib/station_master/schedule/departure.rb', line 4

def platform
  @platform
end

#timeObject (readonly)

Returns the value of attribute time.



4
5
6
# File 'lib/station_master/schedule/departure.rb', line 4

def time
  @time
end

#train_codeObject (readonly)

Returns the value of attribute train_code.



4
5
6
# File 'lib/station_master/schedule/departure.rb', line 4

def train_code
  @train_code
end

#train_typeObject (readonly)

Returns the value of attribute train_type.



4
5
6
# File 'lib/station_master/schedule/departure.rb', line 4

def train_type
  @train_type
end

Instance Method Details

#to_hashObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/station_master/schedule/departure.rb', line 15

def to_hash
  {
    train_code: train_code,
    train_type: train_type,
    destination: destination,
    platform: platform,
    time: time.strftime('%H:%M'),
    delay: delay
  }
end