Class: FinancialMath::ArithmeticProgression
- Inherits:
-
Object
- Object
- FinancialMath::ArithmeticProgression
- Defined in:
- lib/financial_math/arithmetic_progression.rb
Instance Attribute Summary collapse
-
#distance ⇒ Object
readonly
Returns the value of attribute distance.
-
#initial_value ⇒ Object
readonly
Returns the value of attribute initial_value.
-
#times ⇒ Object
readonly
Returns the value of attribute times.
Instance Method Summary collapse
-
#initialize(args) ⇒ ArithmeticProgression
constructor
A new instance of ArithmeticProgression.
- #last_item ⇒ Object
- #sum ⇒ Object
Constructor Details
#initialize(args) ⇒ ArithmeticProgression
Returns a new instance of ArithmeticProgression.
5 6 7 8 9 |
# File 'lib/financial_math/arithmetic_progression.rb', line 5 def initialize(args) @distance = args.fetch(:distance, 1) @times = args.fetch(:times, 1) @initial_value = args.fetch(:initial_value, 0) end |
Instance Attribute Details
#distance ⇒ Object (readonly)
Returns the value of attribute distance.
3 4 5 |
# File 'lib/financial_math/arithmetic_progression.rb', line 3 def distance @distance end |
#initial_value ⇒ Object (readonly)
Returns the value of attribute initial_value.
3 4 5 |
# File 'lib/financial_math/arithmetic_progression.rb', line 3 def initial_value @initial_value end |
#times ⇒ Object (readonly)
Returns the value of attribute times.
3 4 5 |
# File 'lib/financial_math/arithmetic_progression.rb', line 3 def times @times end |
Instance Method Details
#last_item ⇒ Object
11 12 13 |
# File 'lib/financial_math/arithmetic_progression.rb', line 11 def last_item (initial_value + (times - 1.0) * distance).round(2) end |
#sum ⇒ Object
15 16 17 |
# File 'lib/financial_math/arithmetic_progression.rb', line 15 def sum (times / 2.0 * (initial_value + last_item)).round(2) end |