Class: StationData

Inherits:
Object
  • Object
show all
Defined in:
lib/station_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ StationData

Returns a new instance of StationData.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/station_data.rb', line 6

def initialize hash
  @servertime       = hash['Servertime']
  @traincode        = hash['Traincode']
  @station_name     = hash['Stationfullname']
  @station_code     = hash['Stationcode']
  @query_time       = Time.parse(hash['Querytime'])
  @train_date       = hash['Traindate']
  @origin           = hash['Origin']
  @destination      = hash['Destination']
  @origin_time      = Time.parse hash['Origintime']
  @destination_time = Time.parse hash['Destinationtime']
  @status           = hash['Status']
  @last_location    = hash['Lastlocation']
  @duein            = hash['Duein']
  @late             = hash['Late']
  
  # If train origin is station_name, then arrival times will be 00:00, so are adjusted to suit expected origin time.
  # Likewise if destination is station_name, departure times should suit expected destination time.
  # See: http://api.irishrail.ie/realtime/ Point 8
  is_departure_station   = @station_name.eql?(@origin)
  is_terminating_station = @station_name.eql?(@destination)
  
  @exparrival       = is_departure_station ? @origin_time : Time.parse(hash['Exparrival'])
  @expdepart        = is_terminating_station ? @destination_time : Time.parse(hash['Expdepart'])
  @scharrival       = is_departure_station ? @origin_time + @late.to_i : Time.parse(hash['Scharrival'])
  @schdepart        = is_terminating_station ? @destination_time + @late.to_i : Time.parse(hash['Schdepart'])
  @direction        = hash['Direction']
  @train_type       = hash['Traintype']
  
  
end

Instance Attribute Details

#directionObject (readonly)

Returns the value of attribute direction.



2
3
4
# File 'lib/station_data.rb', line 2

def direction
  @direction
end

#dueinObject (readonly) Also known as: due_in

Returns the value of attribute duein.



2
3
4
# File 'lib/station_data.rb', line 2

def duein
  @duein
end

#expdepartObject (readonly)

Returns the value of attribute expdepart.



2
3
4
# File 'lib/station_data.rb', line 2

def expdepart
  @expdepart
end

#last_locationObject (readonly)

Returns the value of attribute last_location.



2
3
4
# File 'lib/station_data.rb', line 2

def last_location
  @last_location
end

#lateObject (readonly)

Returns the value of attribute late.



2
3
4
# File 'lib/station_data.rb', line 2

def late
  @late
end

#query_timeObject (readonly)

Returns the value of attribute query_time.



2
3
4
# File 'lib/station_data.rb', line 2

def query_time
  @query_time
end

#servertimeObject (readonly)

Returns the value of attribute servertime.



2
3
4
# File 'lib/station_data.rb', line 2

def servertime
  @servertime
end

#station_codeObject (readonly) Also known as: code

Returns the value of attribute station_code.



2
3
4
# File 'lib/station_data.rb', line 2

def station_code
  @station_code
end

#station_nameObject (readonly) Also known as: name

Returns the value of attribute station_name.



2
3
4
# File 'lib/station_data.rb', line 2

def station_name
  @station_name
end

#statusObject (readonly)

Returns the value of attribute status.



2
3
4
# File 'lib/station_data.rb', line 2

def status
  @status
end

#train_dateObject (readonly)

Returns the value of attribute train_date.



2
3
4
# File 'lib/station_data.rb', line 2

def train_date
  @train_date
end

#train_typeObject (readonly)

Returns the value of attribute train_type.



2
3
4
# File 'lib/station_data.rb', line 2

def train_type
  @train_type
end

#traincodeObject (readonly)

Returns the value of attribute traincode.



2
3
4
# File 'lib/station_data.rb', line 2

def traincode
  @traincode
end

Instance Method Details

#arrivalObject



46
47
48
# File 'lib/station_data.rb', line 46

def arrival
  {scheduled: @scharrival, expected: @exparrival}
end

#departureObject



50
51
52
# File 'lib/station_data.rb', line 50

def departure
  {scheduled: @schdepart, expected: @expdepart}
end

#destinationObject



42
43
44
# File 'lib/station_data.rb', line 42

def destination
  {name: @destination, time: @destination_time}
end

#late?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/station_data.rb', line 54

def late?
  @late.to_i > 0
end

#originObject



38
39
40
# File 'lib/station_data.rb', line 38

def origin
  {name: @origin, time: @origin_time}
end