Class: RailFeeds::NetworkRail::Schedule::TrainSchedule::Location::Terminating

Inherits:
RailFeeds::NetworkRail::Schedule::TrainSchedule::Location show all
Defined in:
lib/rail_feeds/network_rail/schedule/train_schedule/location/terminating.rb

Overview

A class for holding info about a particular train’s terminating location

Instance Attribute Summary collapse

Attributes inherited from RailFeeds::NetworkRail::Schedule::TrainSchedule::Location

#activity, #platform, #tiploc, #tiploc_suffix

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RailFeeds::NetworkRail::Schedule::TrainSchedule::Location

#==, #hash

Constructor Details

#initialize(**attributes) ⇒ Terminating

Returns a new instance of Terminating.



19
20
21
22
23
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/terminating.rb', line 19

def initialize(**attributes)
  attributes.each do |attribute, value|
    send "#{attribute}=", value
  end
end

Instance Attribute Details

#pathString

Returns:

  • (String)


17
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/terminating.rb', line 17

attr_accessor :scheduled_arrival, :public_arrival, :path

#public_arrivalString

Returns The public arrival time (HHMM).

Returns:

  • (String)

    The public arrival time (HHMM).



17
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/terminating.rb', line 17

attr_accessor :scheduled_arrival, :public_arrival, :path

#scheduled_arrivalString

Returns The scheduled time for arriving at the location.

Returns:

  • (String)

    The scheduled time for arriving at the location.



17
18
19
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/terminating.rb', line 17

def scheduled_arrival
  @scheduled_arrival
end

Class Method Details

.from_cif(line) ⇒ Object

rubocop:disable Metrics/AbcSize Initialize a new terminating from a CIF file line



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/terminating.rb', line 27

def self.from_cif(line)
  fail ArgumentError, "Invalid line:\n#{line}" unless line[0..1].eql?('LT')

  new(
    tiploc: line[2..8].strip,
    tiploc_suffix: line[9].to_i,
    scheduled_arrival: line[10..14].strip,
    public_arrival: line[15..18].strip,
    platform: line[19..21].strip,
    path: line[22..24].strip,
    activity: line[25..36].strip
  )
end

Instance Method Details

#to_cifObject

rubocop:enable Metrics/AbcSize



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/terminating.rb', line 42

def to_cif
  format('%-80.80s', [
    'LT',
    format('%-7.7s', tiploc),
    format('%-1.1s', tiploc_suffix),
    format('%-5.5s', scheduled_arrival),
    format('%-4.4s', public_arrival),
    format('%-3.3s', platform),
    format('%-3.3s', path),
    format('%-12.12s', activity)
  ].join) + "\n"
end

#to_hash_for_jsonObject



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/terminating.rb', line 55

def to_hash_for_json
  {
    location_type: 'LT',
    record_identity: 'LT',
    tiploc_code: tiploc,
    tiploc_instance: tiploc_suffix,
    arrival: scheduled_arrival,
    public_arrival: public_arrival,
    platform: platform,
    path: path
  }
end