Class: JetBluePlaneTracker::Flight

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#destinationObject

Returns the value of attribute destination.



3
4
5
# File 'lib/jetblue_plane_tracker/flight.rb', line 3

def destination
  @destination
end

#legsObject

Returns the value of attribute legs.



3
4
5
# File 'lib/jetblue_plane_tracker/flight.rb', line 3

def legs
  @legs
end

#originObject

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_legsObject



15
16
17
# File 'lib/jetblue_plane_tracker/flight.rb', line 15

def all_legs
	self.legs.each{ |leg| leg.to_json }
end

#to_jsonObject



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_sObject



11
12
13
# File 'lib/jetblue_plane_tracker/flight.rb', line 11

def to_s
	"#{origin} -> #{destination}\n [#{legs}]"
end