Sha256: e4f7b36d3a9ab0c671ba518559edfe7b5783c343bac651b15499a34eb0de9aa7

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

class TrainMovement
  
  attr_reader :location_full_name

  def initialize hash
    @train_code          = hash['TrainCode']
    @train_date          = Time.parse hash['TrainDate']
    @location_code       = hash['LocationCode'] 
    @location_full_name  = hash['LocationFullName']
    @location_order      = hash['LocationOrder'].to_i
    @location_type       = hash['LocationType']
    @train_origin        = hash['TrainOrigin']
    @scheduled_arrival   = Time.parse hash['ScheduledArrival']
    @scheduled_departure = Time.parse hash['ScheduledDeparture']
    @expected_arrival    = Time.parse hash['ExpectedArrival']
    @expected_departure  = Time.parse hash['ExpectedDeparture']
    arrival_time         = hash['Arrival']
    departure_time       = hash['Departure']
    @arrival             = arrival_time.nil? ? @expected_arrival : Time.parse(arrival_time)
    @departure           = departure_time.nil? ? @expected_departure : Time.parse(departure_time)
  end
  
  def location
    {code: @location_code, name: @location_full_name, stop_number: @location_order, type: @location_type}
  end

  def arrival
    {scheduled: @scheduled_arrival, expected: @expected_arrival, actual: @arrival}
  end
  
  def departure
    {scheduled: @scheduled_departure, expected: @expected_departure, actual: @departure}
  end
  
  def train
    {code: @train_code, date: @train_date, origin: @train_origin}
  end

  alias :station :location_full_name
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ierail-0.4.1 lib/train_movement.rb
ierail-0.4.0 lib/train_movement.rb
ierail-0.3.5 lib/train_movement.rb