Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # that it returns an Array is an implementation detail
- # that you have to build it in order to return it is also an implementation detail
- def itinerary(user)
- itinerary = []
- user.bookings.each do |b|
- b.air_itineraries.each do |i|
- i.air_legs.each do |l|
- l.booked_flights.each do |f|
- itinerary << {
- :start_datetime => f.departure_timestamp.to_time,
- :type => 'flight',
- :object => f
- }
- end
- end
- end
- hotels_itinerary(b.booked_hotels, itinerary) # should be possible to do it nicer
- cars_itinerary(b.booked_cars, itinerary) # same
- end #end @user.bookings.each
- itinerary.sort_by { |e| e[:start_datetime] }
- end
- def hotels_itinerary(hotels, itinerary=[])
- itinerary.concat hotels.map do |h|
- {
- :start_datetime => h.checkin.to_time,
- :type => 'hotel',
- :object => h
- }
- end
- end
- def cars_itinerary(cars, itinerary=[])
- itinerary.concat cars.map do |c|
- {
- :start_datetime => c.pickup_timestamp.to_time,
- :type => 'car',
- :object => c
- }
- end
- end
Add Comment
Please, Sign In to add comment