Class: JetBluePlaneTracker::Leg

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#arrivalObject

Returns the value of attribute arrival.



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

def arrival
  @arrival
end

#current_locationObject

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

#dateObject

Returns the value of attribute date.



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

def date
  @date
end

#departureObject

Returns the value of attribute departure.



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

def departure
  @departure
end

#numberObject

Returns the value of attribute number.



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

def number
  @number
end

#progressObject

Returns the value of attribute progress.



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

def progress
  @progress
end

#statusObject

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_progressObject



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_sObject



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