Class: SpreeCmCommissioner::SingleLegTripsQuery

Inherits:
Object
  • Object
show all
Defined in:
app/queries/spree_cm_commissioner/single_leg_trips_query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(origin_id:, destination_id:, date:, route_type: nil, vendor_id: nil, tenant_id: nil, number_of_guests: nil, options: {}) ⇒ SingleLegTripsQuery

rubocop:disable Metrics/ParameterLists



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/queries/spree_cm_commissioner/single_leg_trips_query.rb', line 22

def initialize(origin_id:, # rubocop:disable Metrics/ParameterLists
               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 = date.to_date == Time.zone.today ? Time.zone.now : Time.zone.parse(date.to_s)
  @vendor_id = vendor_id
  @tenant_id = tenant_id
  @number_of_guests = number_of_guests || 1
  @route_type = route_type
  @options = options
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



18
19
20
# File 'app/queries/spree_cm_commissioner/single_leg_trips_query.rb', line 18

def date
  @date
end

#destination_idObject (readonly)

Returns the value of attribute destination_id.



18
19
20
# File 'app/queries/spree_cm_commissioner/single_leg_trips_query.rb', line 18

def destination_id
  @destination_id
end

#number_of_guestsObject (readonly)

Returns the value of attribute number_of_guests.



18
19
20
# File 'app/queries/spree_cm_commissioner/single_leg_trips_query.rb', line 18

def number_of_guests
  @number_of_guests
end

#optionsObject (readonly)

Returns the value of attribute options.



18
19
20
# File 'app/queries/spree_cm_commissioner/single_leg_trips_query.rb', line 18

def options
  @options
end

#origin_idObject (readonly)

Returns the value of attribute origin_id.



18
19
20
# File 'app/queries/spree_cm_commissioner/single_leg_trips_query.rb', line 18

def origin_id
  @origin_id
end

#route_typeObject (readonly)

Returns the value of attribute route_type.



18
19
20
# File 'app/queries/spree_cm_commissioner/single_leg_trips_query.rb', line 18

def route_type
  @route_type
end

#tenant_idObject (readonly)

Returns the value of attribute tenant_id.



18
19
20
# File 'app/queries/spree_cm_commissioner/single_leg_trips_query.rb', line 18

def tenant_id
  @tenant_id
end

#vendor_idObject (readonly)

Returns the value of attribute vendor_id.



18
19
20
# File 'app/queries/spree_cm_commissioner/single_leg_trips_query.rb', line 18

def vendor_id
  @vendor_id
end

Instance Method Details

#callObject



40
41
42
43
44
45
46
47
# File 'app/queries/spree_cm_commissioner/single_leg_trips_query.rb', line 40

def call
  return [] if date < Date.current

  direct_trips.map do |trip|
    result = SpreeCmCommissioner::TripResult.from_trip(trip)
    SpreeCmCommissioner::TripQueryResult.new(trips: [result])
  end
end