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) ⇒ Boolean
rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity.
- #guest_eligible?(guest) ⇒ Boolean
Methods inherited from SpreeCmCommissioner::PricingRule
Instance Method Details
#eligible?(line_item) ⇒ Boolean
rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/spree_cm_commissioner/pricing_rules/nationality.rb', line 8 def eligible?(line_item) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity return false if nationalities.blank? || line_item.guests.blank? targets = Array.wrap(nationalities).map(&:downcase) guest_nationalities = line_item.guests.map { |g| guest_nationality(g) }.compact return false if guest_nationalities.empty? case rule_type when 'all' guest_nationalities.all? { |n| targets.include?(n) } when 'any' guest_nationalities.any? { |n| targets.include?(n) } when 'none' guest_nationalities.any? { |n| targets.exclude?(n) } else false end end |
#guest_eligible?(guest) ⇒ Boolean
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/models/spree_cm_commissioner/pricing_rules/nationality.rb', line 29 def guest_eligible?(guest) return false if nationalities.blank? targets = Array.wrap(nationalities).map(&:downcase) guest_nat = guest_nationality(guest) return false if guest_nat.blank? case rule_type when 'all', 'any' targets.include?(guest_nat) when 'none' targets.exclude?(guest_nat) else false end end |