Class: Financial::BalanceCalculation
- Inherits:
-
Object
- Object
- Financial::BalanceCalculation
- Defined in:
- lib/financial/balance_calculation.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
-
#balances ⇒ Object
Returns the value of attribute balances.
-
#costs ⇒ Object
Returns the value of attribute costs.
-
#revenues ⇒ Object
Returns the value of attribute revenues.
-
#unique_events_dates ⇒ Object
Returns the value of attribute unique_events_dates.
Instance Method Summary collapse
- #calculate! ⇒ Object
- #calculate_costs ⇒ Object
- #calculate_revenues ⇒ Object
-
#initialize(account_instance) ⇒ BalanceCalculation
constructor
A new instance of BalanceCalculation.
Constructor Details
#initialize(account_instance) ⇒ BalanceCalculation
Returns a new instance of BalanceCalculation.
5 6 7 8 9 10 11 12 |
# File 'lib/financial/balance_calculation.rb', line 5 def initialize(account_instance) @balances = [] @account = account_instance @costs = @account.all_costs @revenues = @account.revenues @unique_events_dates = account.unique_events_dates @total = account.total end |
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
3 4 5 |
# File 'lib/financial/balance_calculation.rb', line 3 def account @account end |
#balances ⇒ Object
Returns the value of attribute balances.
3 4 5 |
# File 'lib/financial/balance_calculation.rb', line 3 def balances @balances end |
#costs ⇒ Object
Returns the value of attribute costs.
3 4 5 |
# File 'lib/financial/balance_calculation.rb', line 3 def costs @costs end |
#revenues ⇒ Object
Returns the value of attribute revenues.
3 4 5 |
# File 'lib/financial/balance_calculation.rb', line 3 def revenues @revenues end |
#unique_events_dates ⇒ Object
Returns the value of attribute unique_events_dates.
3 4 5 |
# File 'lib/financial/balance_calculation.rb', line 3 def unique_events_dates @unique_events_dates end |
Instance Method Details
#calculate! ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/financial/balance_calculation.rb', line 14 def calculate! unique_events_dates.collect do |date| @date = date @total -= calculate_costs @total += calculate_revenues Balance.new(@total, date) end end |
#calculate_costs ⇒ Object
23 24 25 26 27 |
# File 'lib/financial/balance_calculation.rb', line 23 def calculate_costs costs_in_date = account.costs_in_date(@date) return 0 if costs_in_date.empty? costs_in_date.collect { |cost| cost.value }.inject(:+) end |
#calculate_revenues ⇒ Object
29 30 31 32 33 |
# File 'lib/financial/balance_calculation.rb', line 29 def calculate_revenues revenues_in_date = account.revenues_in_date(@date) return 0 if revenues_in_date.empty? revenues_in_date.collect {|event| event.value }.inject(:+) end |