Class: UsageCredits::Cost::Fixed
- Defined in:
- lib/usage_credits/cost/fixed.rb
Overview
Fixed credit cost (e.g., always costs 10 credits)
Instance Attribute Summary collapse
-
#period ⇒ Object
readonly
Returns the value of attribute period.
Attributes inherited from Base
Instance Method Summary collapse
- #calculate(params = {}) ⇒ Object
-
#every(period = nil) ⇒ self
Set the recurring period for subscription plans.
-
#initialize(amount) ⇒ Fixed
constructor
A new instance of Fixed.
Methods inherited from Base
Constructor Details
#initialize(amount) ⇒ Fixed
9 10 11 12 |
# File 'lib/usage_credits/cost/fixed.rb', line 9 def initialize(amount) @amount = amount @period = nil # Will default to 1.month in CreditSubscriptionPlan end |
Instance Attribute Details
#period ⇒ Object (readonly)
Returns the value of attribute period.
7 8 9 |
# File 'lib/usage_credits/cost/fixed.rb', line 7 def period @period end |
Instance Method Details
#calculate(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/usage_credits/cost/fixed.rb', line 14 def calculate(params = {}) value = amount.is_a?(Proc) ? amount.call(params) : amount case value when UsageCredits::Cost::Fixed value.calculate(params) else validate_amount!(value) value.to_i end end |
#every(period = nil) ⇒ self
Set the recurring period for subscription plans
28 29 30 31 |
# File 'lib/usage_credits/cost/fixed.rb', line 28 def every(period = nil) @period = period # nil will default to 1.month in CreditSubscriptionPlan self end |