Class: Joyent::Cloud::Pricing::PercentDiscount
- Defined in:
- lib/pricing/discount.rb
Constant Summary
Constants inherited from Discount
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #apply(amount) ⇒ Object
-
#initialize(value) ⇒ PercentDiscount
constructor
A new instance of PercentDiscount.
- #to_s ⇒ Object
Methods inherited from Discount
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
#value ⇒ Object
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_s ⇒ Object
20 21 22 |
# File 'lib/pricing/discount.rb', line 20 def to_s "#{value}%" end |