Class: PromotionalRule

Inherits:
Object
  • Object
show all
Includes:
RuleValidations
Defined in:
lib/wunder/promotional_rule.rb

Constant Summary

Constants included from RuleValidations

RuleValidations::DISCOUNT_TYPES

Instance Attribute Summary collapse

Instance Method Summary collapse

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_typeObject (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

#labelObject (readonly)

Returns the value of attribute label.



6
7
8
# File 'lib/wunder/promotional_rule.rb', line 6

def label
  @label
end

#on_itemObject (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

#ruleObject (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

Returns:

  • (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_priceObject



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_priceObject



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

Returns:

  • (Boolean)


17
18
19
# File 'lib/wunder/promotional_rule.rb', line 17

def eligible?
  raise "Should be defined by the respective rule"
end

#validateObject



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