Class: Promotion

Inherits:
Object
  • Object
show all
Defined in:
lib/wunder/promotion.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, promotion_code) ⇒ Promotion

Returns a new instance of Promotion.



9
10
11
12
13
# File 'lib/wunder/promotion.rb', line 9

def initialize(name, promotion_code)
  @name = name
  @promotion_code = promotion_code
  @promotion_rules = PromotionalRulesCollection.new
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/wunder/promotion.rb', line 5

def name
  @name
end

#promotion_codeObject (readonly)

Returns the value of attribute promotion_code.



5
6
7
# File 'lib/wunder/promotion.rb', line 5

def promotion_code
  @promotion_code
end

#promotion_rulesObject

Returns the value of attribute promotion_rules.



7
8
9
# File 'lib/wunder/promotion.rb', line 7

def promotion_rules
  @promotion_rules
end

Instance Method Details

#add_rule(promotion_rule) ⇒ Object



15
16
17
18
# File 'lib/wunder/promotion.rb', line 15

def add_rule(promotion_rule)
  rule = promotion_rules.find_promotional_rule(promotion_rule)
  promotion_rules.push(promotion_rule) if rule.nil?
end

#add_rules_in_bulk(promotion_rules) ⇒ Object



25
26
27
28
29
# File 'lib/wunder/promotion.rb', line 25

def add_rules_in_bulk(promotion_rules)
  promotion_rules.each do |promotion_rule|
    add_rule(promotion_rule)
  end
end

#remove_rule(promotion_rule) ⇒ Object



20
21
22
23
# File 'lib/wunder/promotion.rb', line 20

def remove_rule(promotion_rule)
  rule = promotion_rules.find_promotional_rule(promotion_rule)
  promotion_rules.delete(rule) unless rule.nil?
end