Class: SpreeCmCommissioner::PricingRules::Nationality

Inherits:
SpreeCmCommissioner::PricingRule show all
Defined in:
app/models/spree_cm_commissioner/pricing_rules/nationality.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
# File 'app/models/spree_cm_commissioner/pricing_rules/nationality.rb', line 8

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

  guests = line_item.guests

  case rule_type
  when 'all'  then guests.all?  { |g| match?(g) }
  when 'any'  then guests.any?  { |g| match?(g) }
  when 'none' then guests.any?  { |g| !match?(g) }
  else false
  end
end

#guest_eligible?(guest) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
# File 'app/models/spree_cm_commissioner/pricing_rules/nationality.rb', line 21

def guest_eligible?(guest)
  return false if nationalities.blank?

  matched = match?(guest)
  rule_type == 'none' ? !matched : matched
end