Class: JetBluePlaneTracker::Leg
- Inherits:
-
Object
- Object
- JetBluePlaneTracker::Leg
- Defined in:
- lib/jetblue_plane_tracker/leg.rb
Instance Attribute Summary collapse
-
#arrival ⇒ Object
Returns the value of attribute arrival.
-
#current_location ⇒ Object
Returns the value of attribute current_location.
-
#date ⇒ Object
Returns the value of attribute date.
-
#departure ⇒ Object
Returns the value of attribute departure.
-
#number ⇒ Object
Returns the value of attribute number.
-
#progress ⇒ Object
Returns the value of attribute progress.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
- #flight_tracker_progress ⇒ Object
-
#initialize(number, date, departure, arrival, status) ⇒ Leg
constructor
A new instance of Leg.
- #to_s ⇒ Object
Constructor Details
#initialize(number, date, departure, arrival, status) ⇒ Leg
Returns a new instance of Leg.
5 6 7 8 9 10 11 12 13 |
# File 'lib/jetblue_plane_tracker/leg.rb', line 5 def initialize(number, date, departure, arrival, status) self.number = number self.date = date self.departure = departure self.arrival = arrival self.status = status self.progress = flight_tracker_progress self.current_location = current_location end |
Instance Attribute Details
#arrival ⇒ Object
Returns the value of attribute arrival.
3 4 5 |
# File 'lib/jetblue_plane_tracker/leg.rb', line 3 def arrival @arrival end |
#current_location ⇒ Object
Returns the value of attribute current_location.
3 4 5 |
# File 'lib/jetblue_plane_tracker/leg.rb', line 3 def current_location @current_location end |
#date ⇒ Object
Returns the value of attribute date.
3 4 5 |
# File 'lib/jetblue_plane_tracker/leg.rb', line 3 def date @date end |
#departure ⇒ Object
Returns the value of attribute departure.
3 4 5 |
# File 'lib/jetblue_plane_tracker/leg.rb', line 3 def departure @departure end |
#number ⇒ Object
Returns the value of attribute number.
3 4 5 |
# File 'lib/jetblue_plane_tracker/leg.rb', line 3 def number @number end |
#progress ⇒ Object
Returns the value of attribute progress.
3 4 5 |
# File 'lib/jetblue_plane_tracker/leg.rb', line 3 def progress @progress end |
#status ⇒ Object
Returns the value of attribute status.
3 4 5 |
# File 'lib/jetblue_plane_tracker/leg.rb', line 3 def status @status end |
Instance Method Details
#flight_tracker_progress ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/jetblue_plane_tracker/leg.rb', line 19 def flight_tracker_progress min_progress = 0 max_progress = 1 progress = 0 # Arrival airport timezone (UTC) utc = self.arrival.airport.timezone # Convert dates to the actual arrival airport timezone current_datetime = DateTime.now.change(:offset => utc.to_s).to_i actual_arrival = self.arrival.actual_takeoff.change(:offset => utc.to_s).to_i actual_departure = self.departure.actual_takeoff.change(:offset => utc.to_s).to_i progress = (current_datetime - actual_departure).to_f / (actual_arrival - actual_departure).to_f # Check if progress is minor than min progress or max progress progress = (progress < min_progress) ? min_progress : progress progress = (progress > max_progress) ? max_progress : progress progress * 100 end |
#to_s ⇒ Object
15 16 17 |
# File 'lib/jetblue_plane_tracker/leg.rb', line 15 def to_s "##{number}\n#{departure}\n#{arrival}\n#{status}\n#{progress}" end |