class RailFeeds::NetworkRail::Schedule::Header::JSON
A class to hole the information from the header row of a json file
Constants
- START_DATE
Attributes
extracted_at[RW]
@!attribute [rw] extracted_at
@return [Time] When the BTD extract happened.
@!attribute [rw] sequence
@return [Integer] Where this file appears in the sequence of extracts.
(Appears to be days since 2012-06-13) @!attribute [r] start_date
@return [Date] Infered from sequence
sequence[RW]
@!attribute [rw] extracted_at
@return [Time] When the BTD extract happened.
@!attribute [rw] sequence
@return [Integer] Where this file appears in the sequence of extracts.
(Appears to be days since 2012-06-13) @!attribute [r] start_date
@return [Date] Infered from sequence
Public Class Methods
from_json(line)
click to toggle source
Initialize a new header from a JSON
file line
# File lib/rail_feeds/network_rail/schedule/header/json.rb, line 29 def self.from_json(line) data = ::JSON.parse(line)['JsonTimetableV1'] metadata = data['Metadata'] new( extracted_at: Time.strptime(data['timestamp'].to_s, '%s').utc, sequence: metadata['sequence'] ) end
new(**attributes)
click to toggle source
# File lib/rail_feeds/network_rail/schedule/header/json.rb, line 22 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/json.rb, line 43 def <=>(other) hash <=> other&.hash end
hash()
click to toggle source
# File lib/rail_feeds/network_rail/schedule/header/json.rb, line 47 def hash sequence&.dup end
start_date()
click to toggle source
# File lib/rail_feeds/network_rail/schedule/header/json.rb, line 39 def start_date START_DATE + sequence.to_i end
to_json(**opts)
click to toggle source
rubocop:disable Metrics/MethodLength
# File lib/rail_feeds/network_rail/schedule/header/json.rb, line 52 def to_json(**opts) { 'JsonTimetableV1' => { 'classification' => 'public', 'timestamp' => extracted_at.to_i, 'owner' => 'Network Rail', 'Sender' => { 'organisation': '', 'application' => 'NTROD', 'component' => 'SCHEDULE' }, 'Metadata' => { 'type' => 'full', 'sequence' => sequence } } }.to_json(**opts) end
to_s()
click to toggle source
rubocop:enable Metrics/MethodLength
# File lib/rail_feeds/network_rail/schedule/header/json.rb, line 72 def to_s "Sequence #{sequence}, proabbly from #{start_date}." end