Class: SpreeCmCommissioner::PricingRules::NationalityGroup
- Inherits:
-
SpreeCmCommissioner::PricingRule
- Object
- Spree::Base
- Base
- SpreeCmCommissioner::PricingRule
- SpreeCmCommissioner::PricingRules::NationalityGroup
- 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
- #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 20 21 |
# File 'app/models/spree_cm_commissioner/pricing_rules/nationality_group.rb', line 8 def eligible?(line_item_context) return false if nationality_groups.blank? || line_item_context.guest_contexts.blank? case rule_type when 'all' line_item_context.guest_contexts.all? { |guest_context| guest_eligible?(guest_context, line_item_context) } when 'any' line_item_context.guest_contexts.any? { |guest_context| guest_eligible?(guest_context, line_item_context) } when 'none' line_item_context.guest_contexts.none? { |guest_context| guest_eligible?(guest_context, line_item_context) } else false end end |
#guest_eligible?(guest_context, _line_item_context) ⇒ 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_context, _line_item_context) guest_nationality_group = guest_context.nationality_group 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 |