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.
-
#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_json ⇒ Object
- #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 |
# 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 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 |
#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
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/jetblue_plane_tracker/leg.rb', line 29 def flight_tracker_progress min_progress = 0 max_progress = 1 progress = 0 current_datetime = Time.now.to_i actual_arrival = Time.parse(self.arrival.actual_takeoff).to_i actual_departure = Time.parse(self.departure.actual_takeoff).to_i progress = (current_datetime - actual_departure).to_f / (actual_arrival- actual_departure).to_f progress = progress < min_progress ? min_progress : progress progress = progress > max_progress ? max_progress : progress progress * 100 end |
#to_json ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/jetblue_plane_tracker/leg.rb', line 18 def to_json { "number" => self.number, "date" => self.date, "departure" => self.departure.to_json, "arrival" => self.arrival.to_json, "status" => self.status, "progress" => self.progress }.to_json end |
#to_s ⇒ Object
14 15 16 |
# File 'lib/jetblue_plane_tracker/leg.rb', line 14 def to_s "##{number}\n#{departure}\n#{arrival}\n#{status}\n#{progress}" end |