Class: SpreeCmCommissioner::PricingRules::NationalityGroup

Inherits:
SpreeCmCommissioner::PricingRule show all
Defined in:
app/models/spree_cm_commissioner/pricing_rules/nationality_group.rb

Constant Summary collapse

RULE_TYPES =
%w[all any none].freeze

Instance Method Summary collapse

Methods inherited from SpreeCmCommissioner::PricingRule

available_rule_types

Instance Method Details

#eligible?(line_item) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/models/spree_cm_commissioner/pricing_rules/nationality_group.rb', line 8

def eligible?(line_item)
  return false if nationality_groups.blank? || line_item.guests.blank?

  case rule_type
  when 'all'
    line_item.guests.all? { |guest| guest_eligible?(guest) }
  when 'any'
    line_item.guests.any? { |guest| guest_eligible?(guest) }
  when 'none'
    line_item.guests.none? { |guest| guest_eligible?(guest) }
  else
    false
  end
end

#guest_eligible?(guest) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'app/models/spree_cm_commissioner/pricing_rules/nationality_group.rb', line 23

def guest_eligible?(guest)
  guest_nationality_group = resolve_guest_nationality_group(guest)
  return false if guest_nationality_group.nil?
  return false if nationality_groups.blank?

  Array.wrap(nationality_groups).map(&:to_sym).include?(guest_nationality_group.to_sym)
end