module RailFeeds::NetworkRail::Schedule::STPIndicator

A collection of methods for working with Short Term Planning indicators. Provides an stp_indicator attribute to the class.

Constants

STP_CIF_MAP

Public Class Methods

included(base) click to toggle source
# File lib/rail_feeds/network_rail/schedule/stp_indicator.rb, line 17
def self.included(base)
  base.extend ClassMethods
end

Public Instance Methods

stp_indicator() click to toggle source

@return [Symbol, nil] Whether (and what kind) of STP record this is:

  • :permanent - This is a permanent (not STP) record

  • :stp_new - This is a new record (not an overlay)

  • :stp_overlay - This record should be overlayed on the permanent one

  • :stp_cancellation - This is an STP cancellation of the permanaent record

# File lib/rail_feeds/network_rail/schedule/stp_indicator.rb, line 26
def stp_indicator
  @stp_indicator ||= ' '
end
stp_indicator=(value) click to toggle source

@param [Symbol, to_s] value Whether (and what kind) of STP record this is:

  • :permanent, 'P' - This is a permanent (not STP) record

  • :stp_new, 'N' - This is a new record (not an overlay)

  • :stp_overlay, 'O' - This record should be overlayed on the permanent one

  • :stp_cancellation, 'C' - This is an STP cancellation of the permanaent record

# File lib/rail_feeds/network_rail/schedule/stp_indicator.rb, line 35
def stp_indicator=(value)
  if STP_CIF_MAP.map(&:last).include?(value.to_s)
    # Convert String / to_s value to relevant Symbol
    value = stp_indicator_from_cif(value)
  end

  unless STP_CIF_MAP.map(&:first).include?(value)
    fail ArgumentError, "value (#{value.inspect}) is invalid, must be any of: " +
                        STP_CIF_MAP.flatten.map(&:inspect).join(', ')
  end

  @stp_indicator = value
end

Protected Instance Methods

stp_indicator_from_cif(value) click to toggle source
# File lib/rail_feeds/network_rail/schedule/stp_indicator.rb, line 55
def stp_indicator_from_cif(value)
  self.class.stp_indicator_from_cif(value)
end
stp_indicator_to_cif() click to toggle source
# File lib/rail_feeds/network_rail/schedule/stp_indicator.rb, line 51
def stp_indicator_to_cif
  self.class.stp_indicator_to_cif stp_indicator
end