Module: TicketSales::TicketSearch
- Included in:
- TicketList
- Defined in:
- lib/ticket_sales/ticket_list.rb
Instance Method Summary collapse
- #cheapest_ticket(from, to) ⇒ Object
- #fastest_ticket(from, to) ⇒ Object
- #get_tickets(from, to) ⇒ Object
- #next_tickets_combined_with(ticket) ⇒ Object
- #previous_tickets_combined_with(ticket) ⇒ Object
- #tickets_arriving_at(location, time) ⇒ Object
- #tickets_connected_with(ticket) ⇒ Object
- #tickets_departing_from(location, time) ⇒ Object
Instance Method Details
#cheapest_ticket(from, to) ⇒ Object
7 8 9 |
# File 'lib/ticket_sales/ticket_list.rb', line 7 def cheapest_ticket(from, to) get_tickets(from, to).min_by(&:price) end |
#fastest_ticket(from, to) ⇒ Object
11 12 13 |
# File 'lib/ticket_sales/ticket_list.rb', line 11 def fastest_ticket(from, to) get_tickets(from, to).min_by(&:travel_length) end |
#get_tickets(from, to) ⇒ Object
3 4 5 |
# File 'lib/ticket_sales/ticket_list.rb', line 3 def get_tickets(from, to) filter Criteria.from(from) & Criteria.to(to) end |
#next_tickets_combined_with(ticket) ⇒ Object
29 30 31 32 33 |
# File 'lib/ticket_sales/ticket_list.rb', line 29 def next_tickets_combined_with(ticket) tickets_departing_from(ticket.to, ticket.arrival_time).map do |current| ticket.combine current end end |
#previous_tickets_combined_with(ticket) ⇒ Object
23 24 25 26 27 |
# File 'lib/ticket_sales/ticket_list.rb', line 23 def previous_tickets_combined_with(ticket) tickets_arriving_at(ticket.from, ticket.departure_time).map do |current| current.combine ticket end end |
#tickets_arriving_at(location, time) ⇒ Object
15 16 17 |
# File 'lib/ticket_sales/ticket_list.rb', line 15 def tickets_arriving_at(location, time) filter Criteria.to(location) & Criteria.arrives_before(time) end |
#tickets_connected_with(ticket) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/ticket_sales/ticket_list.rb', line 35 def tickets_connected_with(ticket) tickets_arriving_at(ticket.from, ticket.departure_time). product(tickets_departing_from(ticket.to, ticket.arrival_time)).map do |left, right| left.combine(ticket).combine(right) end end |
#tickets_departing_from(location, time) ⇒ Object
19 20 21 |
# File 'lib/ticket_sales/ticket_list.rb', line 19 def tickets_departing_from(location, time) filter Criteria.from(location) & Criteria.departs_after(time) end |