Class: SpreeCmCommissioner::TripQuery
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::TripQuery
- Defined in:
- app/queries/spree_cm_commissioner/trip_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 ⇒ Object
-
#initialize(origin_id:, destination_id:, date:, route_type: nil, vendor_id: nil, tenant_id: nil, number_of_guests: nil, options: {}) ⇒ TripQuery
constructor
rubocop:disable Metrics/ParameterLists.
Constructor Details
#initialize(origin_id:, destination_id:, date:, route_type: nil, vendor_id: nil, tenant_id: nil, number_of_guests: nil, options: {}) ⇒ TripQuery
rubocop:disable Metrics/ParameterLists
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'app/queries/spree_cm_commissioner/trip_query.rb', line 5 def initialize(origin_id:, destination_id:, date:, route_type: nil, vendor_id: nil, tenant_id: nil, number_of_guests: nil, options: {}) # rubocop:disable Metrics/ParameterLists @origin_id = origin_id @destination_id = destination_id @date = date.to_date == Time.zone.now.to_date ? 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 = @page = ([:page] || 1).to_i @per_page = [:per_page] end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
3 4 5 |
# File 'app/queries/spree_cm_commissioner/trip_query.rb', line 3 def date @date end |
#destination_id ⇒ Object (readonly)
Returns the value of attribute destination_id.
3 4 5 |
# File 'app/queries/spree_cm_commissioner/trip_query.rb', line 3 def destination_id @destination_id end |
#number_of_guests ⇒ Object (readonly)
Returns the value of attribute number_of_guests.
3 4 5 |
# File 'app/queries/spree_cm_commissioner/trip_query.rb', line 3 def number_of_guests @number_of_guests end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'app/queries/spree_cm_commissioner/trip_query.rb', line 3 def @options end |
#origin_id ⇒ Object (readonly)
Returns the value of attribute origin_id.
3 4 5 |
# File 'app/queries/spree_cm_commissioner/trip_query.rb', line 3 def origin_id @origin_id end |
#route_type ⇒ Object (readonly)
Returns the value of attribute route_type.
3 4 5 |
# File 'app/queries/spree_cm_commissioner/trip_query.rb', line 3 def route_type @route_type end |
#tenant_id ⇒ Object (readonly)
Returns the value of attribute tenant_id.
3 4 5 |
# File 'app/queries/spree_cm_commissioner/trip_query.rb', line 3 def tenant_id @tenant_id end |
#vendor_id ⇒ Object (readonly)
Returns the value of attribute vendor_id.
3 4 5 |
# File 'app/queries/spree_cm_commissioner/trip_query.rb', line 3 def vendor_id @vendor_id end |
Instance Method Details
#call ⇒ Object
18 19 20 21 22 23 24 |
# File 'app/queries/spree_cm_commissioner/trip_query.rb', line 18 def call return Kaminari.paginate_array([]).page(@page).per(@per_page) if date.to_date < Date.current result = direct_trips result += multi_leg_trips if result.empty? || result.size < 3 || ActiveModel::Type::Boolean.new.cast(@options[:include_multi_leg]) Kaminari.paginate_array(result).page(@page).per(@per_page) end |