Class: SpreeCmCommissioner::Accommodations::Find

Inherits:
Object
  • Object
show all
Defined in:
app/finders/spree_cm_commissioner/accommodations/find.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from_date:, to_date:, state_id:, number_of_adults:, number_of_kids:) ⇒ Find

Returns a new instance of Find.



6
7
8
9
10
11
# File 'app/finders/spree_cm_commissioner/accommodations/find.rb', line 6

def initialize(from_date:, to_date:, state_id:, number_of_adults:, number_of_kids:)
  @from_date = from_date
  @to_date = to_date
  @state_id = state_id
  @number_of_guests = number_of_adults.to_i + number_of_kids.to_i
end

Instance Attribute Details

#from_dateObject (readonly)

Returns the value of attribute from_date.



4
5
6
# File 'app/finders/spree_cm_commissioner/accommodations/find.rb', line 4

def from_date
  @from_date
end

#number_of_guestsObject (readonly)

Returns the value of attribute number_of_guests.



4
5
6
# File 'app/finders/spree_cm_commissioner/accommodations/find.rb', line 4

def number_of_guests
  @number_of_guests
end

#state_idObject (readonly)

Returns the value of attribute state_id.



4
5
6
# File 'app/finders/spree_cm_commissioner/accommodations/find.rb', line 4

def state_id
  @state_id
end

#to_dateObject (readonly)

Returns the value of attribute to_date.



4
5
6
# File 'app/finders/spree_cm_commissioner/accommodations/find.rb', line 4

def to_date
  @to_date
end

Instance Method Details

#executeObject



13
14
15
16
17
18
19
20
21
22
# File 'app/finders/spree_cm_commissioner/accommodations/find.rb', line 13

def execute
  scope
    .where(default_state_id: state_id)
    .where(inventory_items: { inventory_date: stay_dates })
    .where('CAST(spree_variants.public_metadata->\'cm_options\'->>\'number-of-adults\' AS INTEGER) +
            CAST(spree_variants.public_metadata->\'cm_options\'->>\'number-of-kids\' AS INTEGER) >= ?', number_of_guests
    )
    .where('inventory_items.quantity_available > 0')
    .distinct
end