Class: SpreeCmCommissioner::PricingRules::Nationality
- Inherits:
-
SpreeCmCommissioner::PricingRule
- Object
- Spree::Base
- Base
- SpreeCmCommissioner::PricingRule
- SpreeCmCommissioner::PricingRules::Nationality
- 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
- #eligible?(line_item_context) ⇒ Boolean
- #guest_eligible?(guest_context, line_item_context) ⇒ Boolean
Methods inherited from SpreeCmCommissioner::PricingRule
Instance Method Details
#eligible?(line_item_context) ⇒ 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_context) return false if nationalities.blank? || line_item_context.guest_contexts.blank? guest_contexts = line_item_context.guest_contexts case rule_type when 'all' then guest_contexts.all? { |gc| match?(gc, line_item_context) } when 'any' then guest_contexts.any? { |gc| match?(gc, line_item_context) } when 'none' then guest_contexts.none? { |gc| match?(gc, line_item_context) } else false end end |
#guest_eligible?(guest_context, line_item_context) ⇒ Boolean
21 22 23 24 25 26 |
# File 'app/models/spree_cm_commissioner/pricing_rules/nationality.rb', line 21 def guest_eligible?(guest_context, line_item_context) return false if nationalities.blank? matched = match?(guest_context, line_item_context) rule_type == 'none' ? !matched : matched end |