Class: RailFeeds::NetworkRail::Schedule::TrainSchedule::Location::Origin

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

Overview

A class for holding information about a particular train’s origin 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) ⇒ Origin

Returns a new instance of Origin.



27
28
29
30
31
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/origin.rb', line 27

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

Instance Attribute Details

#engineering_allowanceFloat

Returns Number of minutes.

Returns:

  • (Float)

    Number of minutes.



23
24
25
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/origin.rb', line 23

attr_accessor :scheduled_departure, :public_departure, :line,
:engineering_allowance, :pathing_allowance,
:performance_allowance

#lineString

Returns:

  • (String)


23
24
25
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/origin.rb', line 23

attr_accessor :scheduled_departure, :public_departure, :line,
:engineering_allowance, :pathing_allowance,
:performance_allowance

#pathing_allowanceFloat

Returns Number of minutes.

Returns:

  • (Float)

    Number of minutes.



23
24
25
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/origin.rb', line 23

attr_accessor :scheduled_departure, :public_departure, :line,
:engineering_allowance, :pathing_allowance,
:performance_allowance

#performance_allowanceFloat

Returns Number of minutes.

Returns:

  • (Float)

    Number of minutes.



23
24
25
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/origin.rb', line 23

attr_accessor :scheduled_departure, :public_departure, :line,
:engineering_allowance, :pathing_allowance,
:performance_allowance

#public_departureString

Returns The public departure time (HHMM).

Returns:

  • (String)

    The public departure time (HHMM).



23
24
25
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/origin.rb', line 23

attr_accessor :scheduled_departure, :public_departure, :line,
:engineering_allowance, :pathing_allowance,
:performance_allowance

#scheduled_departureString

Returns The sheduled time for departing from the location.

Returns:

  • (String)

    The sheduled time for departing from the location.



23
24
25
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/origin.rb', line 23

def scheduled_departure
  @scheduled_departure
end

Class Method Details

.from_cif(line) ⇒ Object

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



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/origin.rb', line 35

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

  new(
    tiploc: line[2..8].strip,
    tiploc_suffix: line[9].to_i,
    scheduled_departure: line[10..14].strip,
    public_departure: line[15..18].strip,
    platform: line[19..21].strip,
    line: line[22..24].strip,
    activity: line[29..40].strip,
    engineering_allowance: parse_allowance(line[25..26].strip),
    pathing_allowance: parse_allowance(line[27..28].strip),
    performance_allowance: parse_allowance(line[41..42].strip)
  )
end

Instance Method Details

#to_cifObject

rubocop:disable Metrics/AbcSize



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

def to_cif
  format('%-80.80s', [
    'LO',
    format('%-7.7s', tiploc),
    format('%-1.1s', tiploc_suffix),
    format('%-5.5s', scheduled_departure),
    format('%-4.4s', public_departure),
    format('%-3.3s', platform),
    format('%-3.3s', line),
    format('%-2.2s', allowance_cif(engineering_allowance)),
    format('%-2.2s', allowance_cif(pathing_allowance)),
    format('%-12.12s', activity),
    format('%-2.2s', allowance_cif(performance_allowance))
  ].join) + "\n"
end

#to_hash_for_jsonObject

rubocop:enable Metrics/AbcSize



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rail_feeds/network_rail/schedule/train_schedule/location/origin.rb', line 71

def to_hash_for_json
  {
    location_type: 'LO',
    record_identity: 'LO',
    tiploc_code: tiploc,
    tiploc_instance: tiploc_suffix,
    departure: scheduled_departure,
    public_departure: public_departure,
    platform: platform,
    line: line,
    engineering_allowance: allowance_json(engineering_allowance),
    pathing_allowance: allowance_json(pathing_allowance),
    performance_allowance: allowance_json(performance_allowance)
  }
end