Class: ExpediaApi::Entities::FlightCombinationLegSegment
- Inherits:
-
Object
- Object
- ExpediaApi::Entities::FlightCombinationLegSegment
- Defined in:
- lib/expedia_api/entities/flight_combination_leg_segment.rb
Overview
class handling each of the flight legs segments
receives data in this format: {
"AirCarrierCode": "AF",
"AirProviderCode": "1",
"AirSegmentIndex":1,
"ArrivalDateTime": "2016-09-07T08:50:00+02:00",
"ArrivalLocationCode": "CDG",
"DepartureDateTime": "2016-09-07T07:00:00+02:00",
"DepartureLocationCode": "TXL",
"FlightDuration": "PT1H50M",
"FlightNumber": "1135",
"OperationSegmentList":{
"OperationSegment":[
{
"AircraftCode": "320",
"ArrivalDateTime": "2016-09-07T08:50:00+02:00",
"ArrivalLocationCode": "CDG",
"DepartureDateTime": "2016-09-07T07:00:00+02:00",
"DepartureLocationCode": "TXL",
"FlightDuration": "PT1H50M",
"OperationSegmentIndex":1
}
]
}
}
Instance Attribute Summary collapse
-
#sibling_segments ⇒ Object
Returns the value of attribute sibling_segments.
Instance Method Summary collapse
-
#arrival_airport_code ⇒ Object
returns the arrival airport code of the segment.
-
#arrival_time ⇒ Object
returns a datetime for the arrival date of the segment.
-
#carrier_code ⇒ Object
returns the carrier code of the segment.
-
#departure_airport_code ⇒ Object
returns the departure airport code of the segment.
-
#departure_time ⇒ Object
returns a departure datetime for the departure time of the segment.
-
#duration_seconds ⇒ Object
returns the duration how long the segment takes.
-
#flight_number ⇒ Object
returns the flight number of the flight.
-
#hours_flight ⇒ Object
returns the hours of the flight, if nor parsable, returns nil.
-
#index ⇒ Object
returns the index of the segment.
-
#initialize(raw_data) ⇒ FlightCombinationLegSegment
constructor
A new instance of FlightCombinationLegSegment.
-
#is_first_segment_of_flight? ⇒ Boolean
returns true if it is the first segment of the flight.
-
#is_last_segment_of_flight? ⇒ Boolean
returns true if it is the last segment of the flight.
-
#minutes_flight ⇒ Object
returns the minutes of the flight, if nor parsable, returns nil.
-
#next_segment ⇒ Object
returns the next segment followed by this segment.
-
#previous_segment ⇒ Object
returns the previous segment preceeded by this segment.
-
#stay_duration_seconds ⇒ Object
returns the time between this segment and the next one.
Constructor Details
#initialize(raw_data) ⇒ FlightCombinationLegSegment
Returns a new instance of FlightCombinationLegSegment.
34 35 36 37 |
# File 'lib/expedia_api/entities/flight_combination_leg_segment.rb', line 34 def initialize(raw_data) @raw_data = raw_data || {} @sibling_segments = [] end |
Instance Attribute Details
#sibling_segments ⇒ Object
Returns the value of attribute sibling_segments.
32 33 34 |
# File 'lib/expedia_api/entities/flight_combination_leg_segment.rb', line 32 def sibling_segments @sibling_segments end |
Instance Method Details
#arrival_airport_code ⇒ Object
returns the arrival airport code of the segment
65 66 67 |
# File 'lib/expedia_api/entities/flight_combination_leg_segment.rb', line 65 def arrival_airport_code @raw_data[:ArrivalLocationCode] end |
#arrival_time ⇒ Object
returns a datetime for the arrival date of the segment
45 46 47 |
# File 'lib/expedia_api/entities/flight_combination_leg_segment.rb', line 45 def arrival_time DateTime.parse(@raw_data[:ArrivalDateTime]) end |
#carrier_code ⇒ Object
returns the carrier code of the segment
55 56 57 |
# File 'lib/expedia_api/entities/flight_combination_leg_segment.rb', line 55 def carrier_code @raw_data[:AirCarrierCode] end |
#departure_airport_code ⇒ Object
returns the departure airport code of the segment
60 61 62 |
# File 'lib/expedia_api/entities/flight_combination_leg_segment.rb', line 60 def departure_airport_code @raw_data[:DepartureLocationCode] end |
#departure_time ⇒ Object
returns a departure datetime for the departure time of the segment
40 41 42 |
# File 'lib/expedia_api/entities/flight_combination_leg_segment.rb', line 40 def departure_time DateTime.parse(@raw_data[:DepartureDateTime]) end |
#duration_seconds ⇒ Object
returns the duration how long the segment takes. returns 0 if it can not be identified.
79 80 81 82 83 84 85 86 87 |
# File 'lib/expedia_api/entities/flight_combination_leg_segment.rb', line 79 def duration_seconds hours = hours_flight minutes = minutes_flight if hours && minutes hours * 3600 + minutes * 60 else 0 end end |
#flight_number ⇒ Object
returns the flight number of the flight
106 107 108 |
# File 'lib/expedia_api/entities/flight_combination_leg_segment.rb', line 106 def flight_number @raw_data[:FlightNumber] end |
#hours_flight ⇒ Object
returns the hours of the flight, if nor parsable, returns nil
90 91 92 93 94 95 |
# File 'lib/expedia_api/entities/flight_combination_leg_segment.rb', line 90 def hours_flight stamp = @raw_data[:FlightDuration].split("PT")[1] stamp.split("H")[0].to_i rescue nil end |
#index ⇒ Object
returns the index of the segment
50 51 52 |
# File 'lib/expedia_api/entities/flight_combination_leg_segment.rb', line 50 def index @raw_data[:AirSegmentIndex] end |
#is_first_segment_of_flight? ⇒ Boolean
returns true if it is the first segment of the flight
117 118 119 120 |
# File 'lib/expedia_api/entities/flight_combination_leg_segment.rb', line 117 def is_first_segment_of_flight? return true if sibling_segments.empty? sibling_segments.sort_by {|segment| segment.index }.first == self end |
#is_last_segment_of_flight? ⇒ Boolean
returns true if it is the last segment of the flight
111 112 113 114 |
# File 'lib/expedia_api/entities/flight_combination_leg_segment.rb', line 111 def is_last_segment_of_flight? return true if sibling_segments.empty? sibling_segments.sort_by {|segment| segment.index }.reverse.first == self end |
#minutes_flight ⇒ Object
returns the minutes of the flight, if nor parsable, returns nil
98 99 100 101 102 103 |
# File 'lib/expedia_api/entities/flight_combination_leg_segment.rb', line 98 def minutes_flight stamp = @raw_data[:FlightDuration].split("PT")[1] stamp.split("H")[1].split("M")[0].to_i rescue nil end |
#next_segment ⇒ Object
returns the next segment followed by this segment
123 124 125 126 |
# File 'lib/expedia_api/entities/flight_combination_leg_segment.rb', line 123 def next_segment return nil if sibling_segments.empty? sibling_segments[sibling_segments.sort_by(&:index).index(self) + 1] end |
#previous_segment ⇒ Object
returns the previous segment preceeded by this segment
129 130 131 132 133 134 135 136 137 |
# File 'lib/expedia_api/entities/flight_combination_leg_segment.rb', line 129 def previous_segment return nil if sibling_segments.empty? index = sibling_segments.sort_by(&:index).index(self) if index && index >= 1 sibling_segments[index - 1] else nil end end |
#stay_duration_seconds ⇒ Object
returns the time between this segment and the next one.
70 71 72 73 74 75 |
# File 'lib/expedia_api/entities/flight_combination_leg_segment.rb', line 70 def stay_duration_seconds return 0 unless next_segment # when we arrive at the next airport, minus when we arrived at this # airport. (next_segment.departure_time.to_time - arrival_time.to_time).to_i end |