class RailFeeds::NetworkRail::Schedule::TrainSchedule::Location::Terminating

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

Attributes

path[RW]

@!attribute [rw] path

@return [String]

@!attribute [rw] scheduled_arrival

@return [String] The scheduled time for arriving at the location.

@!attribute [rw] public_arrival

@return [String] The public arrival time (HHMM).
public_arrival[RW]

@!attribute [rw] path

@return [String]

@!attribute [rw] scheduled_arrival

@return [String] The scheduled time for arriving at the location.

@!attribute [rw] public_arrival

@return [String] The public arrival time (HHMM).
scheduled_arrival[RW]

@!attribute [rw] path

@return [String]

@!attribute [rw] scheduled_arrival

@return [String] The scheduled time for arriving at the location.

@!attribute [rw] public_arrival

@return [String] The public arrival time (HHMM).

Public Class Methods

from_cif(line) click to toggle source

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

# 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
new(**attributes) click to toggle source
# 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

Public Instance Methods

to_cif() click to toggle source

rubocop:disable Style/FormatStringToken

# File lib/rail_feeds/network_rail/schedule/train_schedule/location/terminating.rb, line 43
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_json() click to toggle source

rubocop:enable Style/FormatStringToken

# File lib/rail_feeds/network_rail/schedule/train_schedule/location/terminating.rb, line 57
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