Module: BouchCalculate
- Included in:
- Bouch
- Defined in:
- lib/bouch/calc.rb
Overview
Financial budget calculation and operations for Bouch
Instance Method Summary collapse
-
#calc_assets(assets) ⇒ Object
Calculate asset value aggregate amount.
-
#calc_budget_percentage(total, salary) ⇒ Object
Calculate the percentage of budget of a salary/income.
-
#calc_debt_ratio(debts, assets) ⇒ Object
Calculate a debt ratio: total debts divided by total assets.
-
#calc_debt_ratio_percent(debt_ratio) ⇒ Object
Calculate a debt ratio percentage.
-
#calc_debts(debts) ⇒ Object
Calculate debt/liability aggregate amount.
-
#calc_quarters_raw(budget) ⇒ Object
Calculate each financial quarters budget items, including repeating ones.
-
#calc_quarters_raw_total ⇒ Object
Calculate all financial quarter budget into an aggregate annual budget.
-
#calc_repeating(item) ⇒ Object
Calculate a quarterly repeating budget item amount.
-
#calc_salary(amount, freq) ⇒ Object
Calculate an annual income based on a weekly frequency salary.
Instance Method Details
#calc_assets(assets) ⇒ Object
Calculate asset value aggregate amount
6 7 8 9 10 |
# File 'lib/bouch/calc.rb', line 6 def calc_assets(assets) assets.each_value do |value| @assets.push(value) end end |
#calc_budget_percentage(total, salary) ⇒ Object
Calculate the percentage of budget of a salary/income
13 14 15 |
# File 'lib/bouch/calc.rb', line 13 def calc_budget_percentage(total, salary) ((total.to_f / salary.to_f) * 100).round(2) end |
#calc_debt_ratio(debts, assets) ⇒ Object
Calculate a debt ratio: total debts divided by total assets
25 26 27 |
# File 'lib/bouch/calc.rb', line 25 def calc_debt_ratio(debts, assets) (debts.to_f / assets.to_f).round(4) end |
#calc_debt_ratio_percent(debt_ratio) ⇒ Object
Calculate a debt ratio percentage
30 31 32 |
# File 'lib/bouch/calc.rb', line 30 def calc_debt_ratio_percent(debt_ratio) (debt_ratio.to_f * 100).round(2) end |
#calc_debts(debts) ⇒ Object
Calculate debt/liability aggregate amount
18 19 20 21 22 |
# File 'lib/bouch/calc.rb', line 18 def calc_debts(debts) debts.each_value do |value| @debts.push(value) end end |
#calc_quarters_raw(budget) ⇒ Object
Calculate each financial quarters budget items, including repeating ones
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/bouch/calc.rb', line 45 def calc_quarters_raw(budget) budget.each_value do |items| @quarters[@quarters.length.to_s] = Array.new items.each_value do |value| case value when Hash if value.key?('repeat') @quarters[(@quarters.length - 1).to_s].push(calc_repeating(value['cost'])) end else @quarters[(@quarters.length - 1).to_s].push(value) end end end end |
#calc_quarters_raw_total ⇒ Object
Calculate all financial quarter budget into an aggregate annual budget
62 63 64 |
# File 'lib/bouch/calc.rb', line 62 def calc_quarters_raw_total @quarters['0'].sum + @quarters['1'].sum + @quarters['2'].sum + @quarters['3'].sum end |
#calc_repeating(item) ⇒ Object
Calculate a quarterly repeating budget item amount
35 36 37 |
# File 'lib/bouch/calc.rb', line 35 def calc_repeating(item) (item.to_f * 3).round(2) end |
#calc_salary(amount, freq) ⇒ Object
Calculate an annual income based on a weekly frequency salary
40 41 42 |
# File 'lib/bouch/calc.rb', line 40 def calc_salary(amount, freq) (amount.to_f * (52 / freq)).round(2) end |