class RailFeeds::NetworkRail::Schedule::Header::CIF

A class to hole the information from the header row of a cif file

Attributes

current_file_reference[RW]

@!attribute [rw] file_identity @!attribute [rw] extracted_at

@return [Time] When the BTD extract happened.

@!attribute [rw] current_file_reference

@return [String] Unique reference for the current file.

@!attribute [rw] previous_file_reference

@return [String, nil] Unique reference for the previous file
(the one to apply the update to).

@!attribute [rw] update_indicator

@return [String] 'F' for a full extract, 'U' for an update extract.

@!attribute [rw] version

@return [String] The version of the software that generated the CIF file.

@!attribute [rw] start_date

@return [Date]

@!attribute [rw] end_date

@return [Date]
end_date[RW]

@!attribute [rw] file_identity @!attribute [rw] extracted_at

@return [Time] When the BTD extract happened.

@!attribute [rw] current_file_reference

@return [String] Unique reference for the current file.

@!attribute [rw] previous_file_reference

@return [String, nil] Unique reference for the previous file
(the one to apply the update to).

@!attribute [rw] update_indicator

@return [String] 'F' for a full extract, 'U' for an update extract.

@!attribute [rw] version

@return [String] The version of the software that generated the CIF file.

@!attribute [rw] start_date

@return [Date]

@!attribute [rw] end_date

@return [Date]
extracted_at[RW]

@!attribute [rw] file_identity @!attribute [rw] extracted_at

@return [Time] When the BTD extract happened.

@!attribute [rw] current_file_reference

@return [String] Unique reference for the current file.

@!attribute [rw] previous_file_reference

@return [String, nil] Unique reference for the previous file
(the one to apply the update to).

@!attribute [rw] update_indicator

@return [String] 'F' for a full extract, 'U' for an update extract.

@!attribute [rw] version

@return [String] The version of the software that generated the CIF file.

@!attribute [rw] start_date

@return [Date]

@!attribute [rw] end_date

@return [Date]
file_identity[RW]

@!attribute [rw] file_identity @!attribute [rw] extracted_at

@return [Time] When the BTD extract happened.

@!attribute [rw] current_file_reference

@return [String] Unique reference for the current file.

@!attribute [rw] previous_file_reference

@return [String, nil] Unique reference for the previous file
(the one to apply the update to).

@!attribute [rw] update_indicator

@return [String] 'F' for a full extract, 'U' for an update extract.

@!attribute [rw] version

@return [String] The version of the software that generated the CIF file.

@!attribute [rw] start_date

@return [Date]

@!attribute [rw] end_date

@return [Date]
previous_file_reference[RW]

@!attribute [rw] file_identity @!attribute [rw] extracted_at

@return [Time] When the BTD extract happened.

@!attribute [rw] current_file_reference

@return [String] Unique reference for the current file.

@!attribute [rw] previous_file_reference

@return [String, nil] Unique reference for the previous file
(the one to apply the update to).

@!attribute [rw] update_indicator

@return [String] 'F' for a full extract, 'U' for an update extract.

@!attribute [rw] version

@return [String] The version of the software that generated the CIF file.

@!attribute [rw] start_date

@return [Date]

@!attribute [rw] end_date

@return [Date]
start_date[RW]

@!attribute [rw] file_identity @!attribute [rw] extracted_at

@return [Time] When the BTD extract happened.

@!attribute [rw] current_file_reference

@return [String] Unique reference for the current file.

@!attribute [rw] previous_file_reference

@return [String, nil] Unique reference for the previous file
(the one to apply the update to).

@!attribute [rw] update_indicator

@return [String] 'F' for a full extract, 'U' for an update extract.

@!attribute [rw] version

@return [String] The version of the software that generated the CIF file.

@!attribute [rw] start_date

@return [Date]

@!attribute [rw] end_date

@return [Date]
update_indicator[RW]

@!attribute [rw] file_identity @!attribute [rw] extracted_at

@return [Time] When the BTD extract happened.

@!attribute [rw] current_file_reference

@return [String] Unique reference for the current file.

@!attribute [rw] previous_file_reference

@return [String, nil] Unique reference for the previous file
(the one to apply the update to).

@!attribute [rw] update_indicator

@return [String] 'F' for a full extract, 'U' for an update extract.

@!attribute [rw] version

@return [String] The version of the software that generated the CIF file.

@!attribute [rw] start_date

@return [Date]

@!attribute [rw] end_date

@return [Date]
version[RW]

@!attribute [rw] file_identity @!attribute [rw] extracted_at

@return [Time] When the BTD extract happened.

@!attribute [rw] current_file_reference

@return [String] Unique reference for the current file.

@!attribute [rw] previous_file_reference

@return [String, nil] Unique reference for the previous file
(the one to apply the update to).

@!attribute [rw] update_indicator

@return [String] 'F' for a full extract, 'U' for an update extract.

@!attribute [rw] version

@return [String] The version of the software that generated the CIF file.

@!attribute [rw] start_date

@return [Date]

@!attribute [rw] end_date

@return [Date]

Public Class Methods

from_cif(line) click to toggle source

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

# File lib/rail_feeds/network_rail/schedule/header/cif.rb, line 38
def self.from_cif(line)
  fail ArgumentError, "Invalid line:\n#{line}" unless line[0..1].eql?('HD')

  new(
    file_identity: line[2..21].strip,
    extracted_at: Time.strptime(line[22..31] + 'UTC', '%d%m%y%H%M%Z'),
    current_file_reference: line[32..38].strip,
    previous_file_reference: line[39..45].strip,
    update_indicator: line[46].strip,
    version: line[47].strip,
    start_date: Date.strptime(line[48..53], '%d%m%y'),
    end_date: Date.strptime(line[54..59], '%d%m%y')
  )
end
new(**attributes) click to toggle source
# File lib/rail_feeds/network_rail/schedule/header/cif.rb, line 30
def initialize(**attributes)
  attributes.each do |attribute, value|
    send "#{attribute}=", value
  end
end

Public Instance Methods

==(other) click to toggle source
# File lib/rail_feeds/network_rail/schedule/header/cif.rb, line 64
def ==(other)
  hash == other&.hash
end
full?() click to toggle source

Test if this is a header for a full file

# File lib/rail_feeds/network_rail/schedule/header/cif.rb, line 60
def full?
  update_indicator.eql?('F')
end
hash() click to toggle source
# File lib/rail_feeds/network_rail/schedule/header/cif.rb, line 68
def hash
  current_file_reference&.dup
end
to_cif() click to toggle source

rubocop:disable Metrics/AbcSize rubocop:disable Style/FormatStringToken

# File lib/rail_feeds/network_rail/schedule/header/cif.rb, line 74
def to_cif
  format('%-80.80s', [
    'HD',
    format('%-20.20s', file_identity),
    format('%-10.10s', extracted_at&.strftime('%d%m%y%H%M')),
    format('%-7.7s', current_file_reference),
    format('%-7.7s', previous_file_reference),
    format('%-1.1s', update_indicator),
    format('%-1.1s', version),
    format('%-6.6s', start_date&.strftime('%d%m%y')),
    format('%-6.6s', end_date&.strftime('%d%m%y'))
  ].join) + "\n"
end
to_s() click to toggle source

rubocop:enable Metrics/AbcSize rubocop:enable Style/FormatStringToken

# File lib/rail_feeds/network_rail/schedule/header/cif.rb, line 90
def to_s
  "File #{file_identity.inspect} (version #{version}) " \
    "at #{extracted_at.strftime('%Y-%m-%d %H:%M')}. " \
    "#{full? ? 'A full' : 'An update'} extract " \
    "for #{start_date} to #{end_date}."
end
update?() click to toggle source

Test if this is a header for an update file

# File lib/rail_feeds/network_rail/schedule/header/cif.rb, line 55
def update?
  update_indicator.eql?('U')
end