Class: JetBluePlaneTracker::Flight
- Inherits:
-
Object
- Object
- JetBluePlaneTracker::Flight
- Defined in:
- lib/jetblue_plane_tracker/flight.rb
Instance Attribute Summary collapse
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#legs ⇒ Object
Returns the value of attribute legs.
-
#origin ⇒ Object
Returns the value of attribute origin.
Instance Method Summary collapse
- #all_legs ⇒ Object
-
#initialize(origin, destination, legs) ⇒ Flight
constructor
A new instance of Flight.
- #to_json ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(origin, destination, legs) ⇒ Flight
Returns a new instance of Flight.
5 6 7 8 9 |
# File 'lib/jetblue_plane_tracker/flight.rb', line 5 def initialize(origin, destination, legs) self.origin = Airport.find_by_iata(Airport.parse_airport_iata(origin)) self.destination = Airport.find_by_iata(Airport.parse_airport_iata(destination)) self.legs = legs end |
Instance Attribute Details
#destination ⇒ Object
Returns the value of attribute destination.
3 4 5 |
# File 'lib/jetblue_plane_tracker/flight.rb', line 3 def destination @destination end |
#legs ⇒ Object
Returns the value of attribute legs.
3 4 5 |
# File 'lib/jetblue_plane_tracker/flight.rb', line 3 def legs @legs end |
#origin ⇒ Object
Returns the value of attribute origin.
3 4 5 |
# File 'lib/jetblue_plane_tracker/flight.rb', line 3 def origin @origin end |
Instance Method Details
#all_legs ⇒ Object
15 16 17 |
# File 'lib/jetblue_plane_tracker/flight.rb', line 15 def all_legs self.legs.each{ |leg| leg.to_json } end |
#to_json ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/jetblue_plane_tracker/flight.rb', line 19 def to_json { "origin" => self.origin.to_json, "destination" => self.destination.to_json, "legs" => self.legs.map{ |leg| leg.to_json } } end |
#to_s ⇒ Object
11 12 13 |
# File 'lib/jetblue_plane_tracker/flight.rb', line 11 def to_s "#{origin} -> #{destination}\n [#{legs}]" end |