Class: UsageCredits::Cost::Base
- Inherits:
-
Object
- Object
- UsageCredits::Cost::Base
- Defined in:
- lib/usage_credits/cost/base.rb
Overview
Base class for all credit cost calculations. Subclasses implement different ways of calculating credit costs:
-
Fixed: Simple fixed amount
-
Variable: Amount based on units (MB, etc)
-
Compound: Multiple costs added together
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
Instance Method Summary collapse
- #+(other) ⇒ Object
-
#initialize(amount) ⇒ Base
constructor
A new instance of Base.
- #to_i ⇒ Object
Constructor Details
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
11 12 13 |
# File 'lib/usage_credits/cost/base.rb', line 11 def amount @amount end |
Instance Method Details
#+(other) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/usage_credits/cost/base.rb', line 18 def +(other) case other when Fixed, Variable Compound.new(self, other) else raise ArgumentError, "Cannot add #{other.class} to #{self.class}" end end |
#to_i ⇒ Object
27 28 29 |
# File 'lib/usage_credits/cost/base.rb', line 27 def to_i calculate({}) end |