Class: SpreeCmCommissioner::MultiLegTripsQuery
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::MultiLegTripsQuery
- Includes:
- Transit::TripHelper
- Defined in:
- app/queries/spree_cm_commissioner/multi_leg_trips_query.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#destination_id ⇒ Object
readonly
Returns the value of attribute destination_id.
-
#number_of_guests ⇒ Object
readonly
Returns the value of attribute number_of_guests.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#origin_id ⇒ Object
readonly
Returns the value of attribute origin_id.
-
#route_type ⇒ Object
readonly
Returns the value of attribute route_type.
-
#tenant_id ⇒ Object
readonly
Returns the value of attribute tenant_id.
-
#vendor_id ⇒ Object
readonly
Returns the value of attribute vendor_id.
Instance Method Summary collapse
- #call ⇒ Array<TripQueryResult>
-
#initialize(origin_id:, destination_id:, date:, route_type: nil, vendor_id: nil, tenant_id: nil, number_of_guests: nil, options: {}) ⇒ MultiLegTripsQuery
constructor
rubocop:disable Metrics/ParameterLists.
Methods included from Transit::TripHelper
#minutes_since_midnight, #normalize_date, #parse_date, #parse_time
Constructor Details
#initialize(origin_id:, destination_id:, date:, route_type: nil, vendor_id: nil, tenant_id: nil, number_of_guests: nil, options: {}) ⇒ MultiLegTripsQuery
rubocop:disable Metrics/ParameterLists
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/queries/spree_cm_commissioner/multi_leg_trips_query.rb', line 31 def initialize( # rubocop:disable Metrics/ParameterLists origin_id:, destination_id:, date:, route_type: nil, vendor_id: nil, tenant_id: nil, number_of_guests: nil, options: {} ) @origin_id = origin_id @destination_id = destination_id @date = normalize_date(date) @vendor_id = vendor_id @tenant_id = tenant_id @number_of_guests = number_of_guests || 1 @route_type = route_type @options = end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
22 23 24 |
# File 'app/queries/spree_cm_commissioner/multi_leg_trips_query.rb', line 22 def date @date end |
#destination_id ⇒ Object (readonly)
Returns the value of attribute destination_id.
22 23 24 |
# File 'app/queries/spree_cm_commissioner/multi_leg_trips_query.rb', line 22 def destination_id @destination_id end |
#number_of_guests ⇒ Object (readonly)
Returns the value of attribute number_of_guests.
22 23 24 |
# File 'app/queries/spree_cm_commissioner/multi_leg_trips_query.rb', line 22 def number_of_guests @number_of_guests end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
22 23 24 |
# File 'app/queries/spree_cm_commissioner/multi_leg_trips_query.rb', line 22 def @options end |
#origin_id ⇒ Object (readonly)
Returns the value of attribute origin_id.
22 23 24 |
# File 'app/queries/spree_cm_commissioner/multi_leg_trips_query.rb', line 22 def origin_id @origin_id end |
#route_type ⇒ Object (readonly)
Returns the value of attribute route_type.
22 23 24 |
# File 'app/queries/spree_cm_commissioner/multi_leg_trips_query.rb', line 22 def route_type @route_type end |
#tenant_id ⇒ Object (readonly)
Returns the value of attribute tenant_id.
22 23 24 |
# File 'app/queries/spree_cm_commissioner/multi_leg_trips_query.rb', line 22 def tenant_id @tenant_id end |
#vendor_id ⇒ Object (readonly)
Returns the value of attribute vendor_id.
22 23 24 |
# File 'app/queries/spree_cm_commissioner/multi_leg_trips_query.rb', line 22 def vendor_id @vendor_id end |
Instance Method Details
#call ⇒ Array<TripQueryResult>
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/queries/spree_cm_commissioner/multi_leg_trips_query.rb', line 52 def call return [] if date.to_date < Date.current trip_legs = find_trip_legs_with_inventory_validation(date: date.to_date) return [] if trip_legs.empty? legs_by_parent = group_legs(trip_legs: trip_legs) leg_ids = legs_by_parent.values.flatten.uniq legs_by_id = preload_leg_trips(leg_ids: leg_ids) parents_by_id = {} trip_legs.each do |leg| parent_id = leg.parent_trip_id next if parents_by_id[parent_id] parents_by_id[parent_id] = { id: leg.parent_trip_id, origin_place_id: leg.parent_origin_place_id, destination_place_id: leg.parent_destination_place_id, vendor_id: leg.parent_vendor_id } end build_trip_query_results(trip_legs, legs_by_parent, legs_by_id, parents_by_id) end |