Class: ExpediaApi::Entities::FlightCombinationLeg
- Inherits:
-
Object
- Object
- ExpediaApi::Entities::FlightCombinationLeg
- Defined in:
- lib/expedia_api/entities/flight_combination_leg.rb
Overview
wrapper class for each of the flight legs
Instance Method Summary collapse
-
#extract_segments ⇒ Object
extracts the segments of the flight from the json.
-
#hours_all_segments ⇒ Object
returns the hours of the flight, if nor parsable, returns nil.
-
#index ⇒ Object
returns the index of the flight leg.
-
#initialize(raw_data) ⇒ FlightCombinationLeg
constructor
The raw data by the API looks like this:.
-
#is_return_flight? ⇒ Boolean
returns true if we have a return flight leg.
-
#is_to_flight? ⇒ Boolean
returns true if we have a to flight.
-
#minutes_all_segments ⇒ Object
returns the minutes of the flight, if nor parsable, returns nil.
-
#segments ⇒ Object
returns the flight segments of the flight.
-
#total_duration_seconds ⇒ Object
returns the total time it will in seconds.
Constructor Details
#initialize(raw_data) ⇒ FlightCombinationLeg
The raw data by the API looks like this:
{
"AirLegIndex":1,
"AirSegmentList":{
"AirSegment":[
{
"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
}
]
}
},
{
"AirCarrierCode": "TN",
"AirProviderCode": "1",
"AirSegmentIndex":2,
"ArrivalDateTime": "2016-09-07T22:00:00-10:00",
"ArrivalLocationCode": "PPT",
"DepartureDateTime": "2016-09-07T11:30:00+02:00",
"DepartureLocationCode": "CDG",
"FlightDuration": "PT22H30M",
"FlightNumber": "7",
"OperationSegmentList":{
"OperationSegment":[
{
"AircraftCode": "343",
"ArrivalDateTime": "2016-09-07T22:00:00-10:00",
"ArrivalLocationCode": "PPT",
"DepartureDateTime": "2016-09-07T11:30:00+02:00",
"DepartureLocationCode": "CDG",
"FlightDuration": "PT22H30M",
"OperationSegmentIndex":1
}
]
}
},
{
"AirCarrierCode": "VT",
"AirProviderCode": "1",
"AirSegmentIndex":3,
"ArrivalDateTime": "2016-09-08T07:35:00-10:00",
"ArrivalLocationCode": "BOB",
"DepartureDateTime": "2016-09-08T06:45:00-10:00",
"DepartureLocationCode": "PPT",
"FlightDuration": "PT50M",
"FlightNumber": "487",
"OperationSegmentList":{
"OperationSegment":[
{
"AircraftCode": "AT7",
"ArrivalDateTime": "2016-09-08T07:35:00-10:00",
"ArrivalLocationCode": "BOB",
"DepartureDateTime": "2016-09-08T06:45:00-10:00",
"DepartureLocationCode": "PPT",
"FlightDuration": "PT50M",
"OperationSegmentIndex":1
}
]
}
}
]
},
"FlightDuration": "PT36H35M0S",
"TotalStops":2
}
90 91 92 |
# File 'lib/expedia_api/entities/flight_combination_leg.rb', line 90 def initialize(raw_data) @raw_data = raw_data || {} end |
Instance Method Details
#extract_segments ⇒ Object
extracts the segments of the flight from the json
108 109 110 |
# File 'lib/expedia_api/entities/flight_combination_leg.rb', line 108 def extract_segments @raw_data[:AirSegmentList][:AirSegment] || [] end |
#hours_all_segments ⇒ Object
returns the hours of the flight, if nor parsable, returns nil
126 127 128 129 130 131 |
# File 'lib/expedia_api/entities/flight_combination_leg.rb', line 126 def hours_all_segments stamp = @raw_data[:FlightDuration].split("PT")[1] stamp.split("H")[0].to_i rescue nil end |
#index ⇒ Object
returns the index of the flight leg
142 143 144 |
# File 'lib/expedia_api/entities/flight_combination_leg.rb', line 142 def index @raw_data[:AirLegIndex].to_i end |
#is_return_flight? ⇒ Boolean
returns true if we have a return flight leg.
152 153 154 |
# File 'lib/expedia_api/entities/flight_combination_leg.rb', line 152 def is_return_flight? index == 2 end |
#is_to_flight? ⇒ Boolean
returns true if we have a to flight
147 148 149 |
# File 'lib/expedia_api/entities/flight_combination_leg.rb', line 147 def is_to_flight? index == 1 end |
#minutes_all_segments ⇒ Object
returns the minutes of the flight, if nor parsable, returns nil
134 135 136 137 138 139 |
# File 'lib/expedia_api/entities/flight_combination_leg.rb', line 134 def minutes_all_segments stamp = @raw_data[:FlightDuration].split("PT")[1] stamp.split("H")[1].split("M")[0].to_i rescue nil end |
#segments ⇒ Object
returns the flight segments of the flight
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/expedia_api/entities/flight_combination_leg.rb', line 95 def segments @segments ||= begin segments = extract_segments.map do |segment| FlightCombinationLegSegment.new(segment) end segments.each do |segment| segment.sibling_segments = segments end segments end end |
#total_duration_seconds ⇒ Object
returns the total time it will in seconds.
format by expedia: “PT21H50M”
115 116 117 118 119 120 121 122 123 |
# File 'lib/expedia_api/entities/flight_combination_leg.rb', line 115 def total_duration_seconds hours = hours_all_segments minutes = minutes_all_segments if hours && minutes hours * 3600 + minutes * 60 else 0 end end |