Class: PromotionalRule
- Inherits:
-
Object
- Object
- PromotionalRule
- Includes:
- RuleValidations
- Defined in:
- lib/wunder/promotional_rule.rb
Direct Known Subclasses
Promotional::Rule::BasketRule, Promotional::Rule::ItemQuantityPriceRule
Constant Summary
Constants included from RuleValidations
RuleValidations::DISCOUNT_TYPES
Instance Attribute Summary collapse
-
#discount_type ⇒ Object
readonly
Returns the value of attribute discount_type.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#on_item ⇒ Object
readonly
Returns the value of attribute on_item.
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
Instance Method Summary collapse
- #adjustable?(_total) ⇒ Boolean
- #calculate_discounted_price ⇒ Object
- #calculate_total(arg) ⇒ Object
- #calculate_total_discounted_price ⇒ Object
- #eligible? ⇒ Boolean
-
#initialize(label, discount_type, on_item, rule, no_validate = false) ⇒ PromotionalRule
constructor
A new instance of PromotionalRule.
- #validate ⇒ Object
Methods included from RuleValidations
#boolean?, #check_discount_type, #either_should_be_present, #should_be_a_boolean, #should_be_a_number, #should_be_more_than, #should_be_present
Constructor Details
#initialize(label, discount_type, on_item, rule, no_validate = false) ⇒ PromotionalRule
Returns a new instance of PromotionalRule.
8 9 10 11 12 13 14 15 |
# File 'lib/wunder/promotional_rule.rb', line 8 def initialize(label, discount_type, on_item, rule, no_validate = false) @label = label @discount_type = discount_type @on_item = on_item @rule = rule validate if no_validate == false end |
Instance Attribute Details
#discount_type ⇒ Object (readonly)
Returns the value of attribute discount_type.
6 7 8 |
# File 'lib/wunder/promotional_rule.rb', line 6 def discount_type @discount_type end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
6 7 8 |
# File 'lib/wunder/promotional_rule.rb', line 6 def label @label end |
#on_item ⇒ Object (readonly)
Returns the value of attribute on_item.
6 7 8 |
# File 'lib/wunder/promotional_rule.rb', line 6 def on_item @on_item end |
#rule ⇒ Object (readonly)
Returns the value of attribute rule.
6 7 8 |
# File 'lib/wunder/promotional_rule.rb', line 6 def rule @rule end |
Instance Method Details
#adjustable?(_total) ⇒ Boolean
21 22 23 |
# File 'lib/wunder/promotional_rule.rb', line 21 def adjustable?(_total) raise "Should be defined by the respective rule" end |
#calculate_discounted_price ⇒ Object
32 33 34 |
# File 'lib/wunder/promotional_rule.rb', line 32 def calculate_discounted_price raise "Should be defined by the respective rule" end |
#calculate_total(arg) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/wunder/promotional_rule.rb', line 40 def calculate_total(arg) if on_item == true rule.calculate_discounted_price(arg, discount_type) else rule.calculate_total_discounted_price(arg, discount_type) end end |
#calculate_total_discounted_price ⇒ Object
36 37 38 |
# File 'lib/wunder/promotional_rule.rb', line 36 def calculate_total_discounted_price raise "Should be defined by the respective rule" end |
#eligible? ⇒ Boolean
17 18 19 |
# File 'lib/wunder/promotional_rule.rb', line 17 def eligible? raise "Should be defined by the respective rule" end |
#validate ⇒ Object
25 26 27 28 29 30 |
# File 'lib/wunder/promotional_rule.rb', line 25 def validate should_be_present("label", label) check_discount_type(discount_type) should_be_a_boolean("PromotionaRule::OnItem", on_item) should_be_present("PromotionalRule::Rule", rule) end |