class Skyscanner::RouteInfo
Route
info
Attributes
carriers[R]
places[R]
quotes[R]
routes[R]
Public Class Methods
find(meta)
click to toggle source
# File lib/movlog/routes.rb, line 13 def self.find(meta) data = SkyscannerApi.routes_info(meta) new(data) end
new(data)
click to toggle source
# File lib/movlog/routes.rb, line 9 def initialize(data) load_data(data) end
Public Instance Methods
parse_flights()
click to toggle source
# File lib/movlog/routes.rb, line 18 def parse_flights @quotes.map do |quo| data = { min_price: quo['MinPrice'], direct: quo['Direct'], carriers: get_carriers(quo['OutboundLeg']['CarrierIds']), origin: get_place(quo['OutboundLeg']['OriginId']), destination: get_place(quo['OutboundLeg']['DestinationId']), date: quo['OutboundLeg']['DepartureDate'] } Flight.new(data) end end
Private Instance Methods
get_carriers(carrier_ids)
click to toggle source
# File lib/movlog/routes.rb, line 62 def get_carriers(carrier_ids) carrier_ids.map { |cid| @carriers[cid] } end
get_place(place_id)
click to toggle source
# File lib/movlog/routes.rb, line 58 def get_place(place_id) @places[place_id] end
load_carriers(carriers)
click to toggle source
# File lib/movlog/routes.rb, line 51 def load_carriers(carriers) @carriers = {} carriers.each do |carrier| @carriers[carrier['CarrierId']] = carrier['Name'] end end
load_data(data)
click to toggle source
# File lib/movlog/routes.rb, line 33 def load_data(data) @routes = data['Routes'] load_quotes(data['Quotes']) load_places(data['Places']) load_carriers(data['Carriers']) end
load_places(places)
click to toggle source
# File lib/movlog/routes.rb, line 46 def load_places(places) @places = {} places.each { |place| @places[place['PlaceId']] = Place.new(place) } end
load_quotes(quotes)
click to toggle source
# File lib/movlog/routes.rb, line 40 def load_quotes(quotes) @quotes = quotes.select do |quo| quo['OutboundLeg']['CarrierIds'].length.nonzero? end end