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
Methods inherited from SpreeCmCommissioner::PricingRule
Instance Method Details
#eligible?(line_item) ⇒ 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) return false if 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
28 29 30 31 32 33 |
# File 'app/models/spree_cm_commissioner/pricing_rules/age_group.rb', line 28 def guest_eligible?(guest) guest_age_group = resolve_guest_age_group(guest) return false if guest_age_group.nil? Array.wrap(age_groups).map(&:to_sym).include?(guest_age_group.to_sym) end |