Class: SpreeCmCommissioner::PricingRules::AgeGroup
- Inherits:
-
SpreeCmCommissioner::PricingRule
- Object
- Spree::Base
- Base
- SpreeCmCommissioner::PricingRule
- SpreeCmCommissioner::PricingRules::AgeGroup
- Defined in:
- app/models/spree_cm_commissioner/pricing_rules/age_group.rb
Constant Summary collapse
- AGE_GROUPS =
{ child: [0, 12], adult: [13, 99] }.freeze
- 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
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/models/spree_cm_commissioner/pricing_rules/age_group.rb', line 13 def eligible?(line_item_context) return false if 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
28 29 30 31 32 33 |
# File 'app/models/spree_cm_commissioner/pricing_rules/age_group.rb', line 28 def guest_eligible?(guest_context, _line_item_context) guest_age_group = guest_context.age_group return false if guest_age_group.nil? Array.wrap(age_groups).map(&:to_sym).include?(guest_age_group.to_sym) end |