Class: InterestDays::Calculator

Inherits:
Object
  • Object
show all
Defined in:
lib/interest_days/calculator.rb

Overview

Main calculator class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_date:, end_date:, strategy:) ⇒ Calculator

Returns a new instance of Calculator.



8
9
10
11
12
# File 'lib/interest_days/calculator.rb', line 8

def initialize(start_date:, end_date:, strategy:)
  @start_date = start_date
  @end_date = end_date
  @strategy = strategies[strategy.to_sym]
end

Instance Attribute Details

#end_dateObject

Returns the value of attribute end_date.



6
7
8
# File 'lib/interest_days/calculator.rb', line 6

def end_date
  @end_date
end

#start_dateObject

Returns the value of attribute start_date.



6
7
8
# File 'lib/interest_days/calculator.rb', line 6

def start_date
  @start_date
end

#strategyObject

Returns the value of attribute strategy.



6
7
8
# File 'lib/interest_days/calculator.rb', line 6

def strategy
  @strategy
end

Instance Method Details

#interest_day_count_factorObject

Raises:

  • (StandardError)


14
15
16
17
18
# File 'lib/interest_days/calculator.rb', line 14

def interest_day_count_factor
  raise StandardError, "Strategy is not set" if @strategy.nil?

  @strategy.new(start_date: @start_date, end_date: @end_date).day_count_factor
end