Class: StationData
- Inherits:
-
Object
- Object
- StationData
- Defined in:
- lib/station_data.rb
Instance Attribute Summary collapse
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#duein ⇒ Object
(also: #due_in)
readonly
Returns the value of attribute duein.
-
#expdepart ⇒ Object
readonly
Returns the value of attribute expdepart.
-
#last_location ⇒ Object
readonly
Returns the value of attribute last_location.
-
#late ⇒ Object
readonly
Returns the value of attribute late.
-
#query_time ⇒ Object
readonly
Returns the value of attribute query_time.
-
#servertime ⇒ Object
readonly
Returns the value of attribute servertime.
-
#station_code ⇒ Object
(also: #code)
readonly
Returns the value of attribute station_code.
-
#station_name ⇒ Object
(also: #name)
readonly
Returns the value of attribute station_name.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#train_date ⇒ Object
readonly
Returns the value of attribute train_date.
-
#train_type ⇒ Object
readonly
Returns the value of attribute train_type.
-
#traincode ⇒ Object
readonly
Returns the value of attribute traincode.
Instance Method Summary collapse
- #arrival ⇒ Object
- #departure ⇒ Object
- #destination ⇒ Object
-
#initialize(hash) ⇒ StationData
constructor
A new instance of StationData.
- #late? ⇒ Boolean
- #origin ⇒ Object
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
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
2 3 4 |
# File 'lib/station_data.rb', line 2 def direction @direction end |
#duein ⇒ Object (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 |
#expdepart ⇒ Object (readonly)
Returns the value of attribute expdepart.
2 3 4 |
# File 'lib/station_data.rb', line 2 def expdepart @expdepart end |
#last_location ⇒ Object (readonly)
Returns the value of attribute last_location.
2 3 4 |
# File 'lib/station_data.rb', line 2 def last_location @last_location end |
#late ⇒ Object (readonly)
Returns the value of attribute late.
2 3 4 |
# File 'lib/station_data.rb', line 2 def late @late end |
#query_time ⇒ Object (readonly)
Returns the value of attribute query_time.
2 3 4 |
# File 'lib/station_data.rb', line 2 def query_time @query_time end |
#servertime ⇒ Object (readonly)
Returns the value of attribute servertime.
2 3 4 |
# File 'lib/station_data.rb', line 2 def servertime @servertime end |
#station_code ⇒ Object (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_name ⇒ Object (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 |
#status ⇒ Object (readonly)
Returns the value of attribute status.
2 3 4 |
# File 'lib/station_data.rb', line 2 def status @status end |
#train_date ⇒ Object (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_type ⇒ Object (readonly)
Returns the value of attribute train_type.
2 3 4 |
# File 'lib/station_data.rb', line 2 def train_type @train_type end |
#traincode ⇒ Object (readonly)
Returns the value of attribute traincode.
2 3 4 |
# File 'lib/station_data.rb', line 2 def traincode @traincode end |
Instance Method Details
#arrival ⇒ Object
46 47 48 |
# File 'lib/station_data.rb', line 46 def arrival {scheduled: @scharrival, expected: @exparrival} end |
#departure ⇒ Object
50 51 52 |
# File 'lib/station_data.rb', line 50 def departure {scheduled: @schdepart, expected: @expdepart} end |
#destination ⇒ Object
42 43 44 |
# File 'lib/station_data.rb', line 42 def destination {name: @destination, time: @destination_time} end |
#late? ⇒ Boolean
54 55 56 |
# File 'lib/station_data.rb', line 54 def late? @late.to_i > 0 end |
#origin ⇒ Object
38 39 40 |
# File 'lib/station_data.rb', line 38 def origin {name: @origin, time: @origin_time} end |