Class: UsageCredits::Cost::Variable
- Defined in:
- lib/usage_credits/cost/variable.rb
Overview
Variable credit cost based on units (e.g., 1 credit per MB)
Instance Attribute Summary collapse
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
Attributes inherited from Base
Instance Method Summary collapse
- #calculate(params = {}) ⇒ Object
-
#initialize(amount, unit) ⇒ Variable
constructor
A new instance of Variable.
Methods inherited from Base
Constructor Details
#initialize(amount, unit) ⇒ Variable
9 10 11 12 |
# File 'lib/usage_credits/cost/variable.rb', line 9 def initialize(amount, unit) super(amount) @unit = unit.to_sym end |
Instance Attribute Details
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
7 8 9 |
# File 'lib/usage_credits/cost/variable.rb', line 7 def unit @unit end |
Instance Method Details
#calculate(params = {}) ⇒ Object
14 15 16 17 18 |
# File 'lib/usage_credits/cost/variable.rb', line 14 def calculate(params = {}) size = extract_size(params) raw_cost = amount * size CreditCalculator.apply_rounding(raw_cost) end |