Class: Joyent::Cloud::Pricing::PercentDiscount

Inherits:
Discount
  • Object
show all
Defined in:
lib/pricing/discount.rb

Constant Summary

Constants inherited from Discount

Discount::CALCULATORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Discount

type

Constructor Details

#initialize(value) ⇒ PercentDiscount

Returns a new instance of PercentDiscount.



11
12
13
14
# File 'lib/pricing/discount.rb', line 11

def initialize(value)
  @value = value
  raise 'Discount value must be between 0% and 100%' unless self.value <= 100 && self.value >= 0
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



10
11
12
# File 'lib/pricing/discount.rb', line 10

def value
  @value
end

Instance Method Details

#apply(amount) ⇒ Object



16
17
18
# File 'lib/pricing/discount.rb', line 16

def apply(amount)
  amount - 0.01 * value * amount
end

#to_sObject



20
21
22
# File 'lib/pricing/discount.rb', line 20

def to_s
  "#{value}%"
end