Class: Promotional::Rule::BasketRule
- Inherits:
-
PromotionalRule
- Object
- PromotionalRule
- Promotional::Rule::BasketRule
- Defined in:
- lib/wunder/promotional/rule/basket_rule.rb
Constant Summary
Constants included from RuleValidations
RuleValidations::DISCOUNT_TYPES
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from PromotionalRule
#discount_type, #label, #on_item, #rule
Instance Method Summary collapse
- #adjustable?(total) ⇒ Boolean
- #calculate_total_discounted_price(total, discount_type) ⇒ Object
- #eligible?(_item) ⇒ Boolean
-
#initialize(value, no_validate = false) ⇒ BasketRule
constructor
A new instance of BasketRule.
- #validate ⇒ Object
Methods inherited from PromotionalRule
#calculate_discounted_price, #calculate_total
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(value, no_validate = false) ⇒ BasketRule
Returns a new instance of BasketRule.
6 7 8 9 10 |
# File 'lib/wunder/promotional/rule/basket_rule.rb', line 6 def initialize(value, no_validate = false) @value = value validate if no_validate == false end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
4 5 6 |
# File 'lib/wunder/promotional/rule/basket_rule.rb', line 4 def value @value end |
Instance Method Details
#adjustable?(total) ⇒ Boolean
12 13 14 15 |
# File 'lib/wunder/promotional/rule/basket_rule.rb', line 12 def adjustable?(total) return true if total > value false end |
#calculate_total_discounted_price(total, discount_type) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/wunder/promotional/rule/basket_rule.rb', line 21 def calculate_total_discounted_price(total, discount_type) if discount_type == "percentage" discount_price = total - ((total * value) / 100) elsif discount_type == "flat_rate" discount_price = total end discount_price end |
#eligible?(_item) ⇒ Boolean
17 18 19 |
# File 'lib/wunder/promotional/rule/basket_rule.rb', line 17 def eligible?(_item) false end |
#validate ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/wunder/promotional/rule/basket_rule.rb', line 31 def validate should_be_present("BasketRule::Value", value) should_be_a_number("BasketRule::Value", value) should_be_more_than("BasketRule::MinQuantity", value, 1) end |