Class: Bouch
- Inherits:
-
Object
- Object
- Bouch
- Includes:
- BouchCalculate
- Defined in:
- lib/bouch.rb,
lib/bouch/cli.rb,
lib/bouch/example.rb,
lib/bouch/version.rb
Overview
Calculate and create simple financial budgets by parsing a single YAML file as input
Defined Under Namespace
Classes: CLI
Constant Summary collapse
- SEPARATOR =
Paint["\u2500" * 42, :faint]
- EXAMPLE_POUCH =
<<~YAML --- Budget: Q1: Rent: cost: 1000 repeat: true foo: 20 bar: 5 Q2: Rent: cost: 1000 repeat: true fizz: 20 buzz: 5 Q3: Rent: cost: 1000 repeat: true bubble: 20 sort: 5 Q4: Rent: cost: 1000 repeat: true baz: 20 qax: 5 Salary: quantity: 1108.00 frequency: 2 Assets: foo: 500 Equity: bar: 500 Debts: baz: 120 qax: 300 ... YAML
- VERSION =
'2.0.1'
Instance Attribute Summary collapse
-
#assets ⇒ Object
Returns the value of attribute assets.
-
#debts ⇒ Object
Returns the value of attribute debts.
-
#equity ⇒ Object
Returns the value of attribute equity.
-
#net_worth ⇒ Object
Returns the value of attribute net_worth.
-
#pouch ⇒ Object
Returns the value of attribute pouch.
-
#quarters ⇒ Object
Returns the value of attribute quarters.
Instance Method Summary collapse
-
#initialize(file) ⇒ Bouch
constructor
A new instance of Bouch.
-
#show_annual_income ⇒ Object
Summarize and show annual income.
-
#show_annual_total ⇒ Object
Summarize and show the aggregate annual budget totals.
-
#show_assets_total ⇒ Object
Summarize and show aggregate asset totals.
-
#show_budget ⇒ Object
Summarize and show all aggregate components of the quarterly, annual budgets, assets.
-
#show_budget_percentage ⇒ Object
Summarize and show the aggregate annual budget as a percentage of income.
-
#show_debt_ratio ⇒ Object
Summarize and show debt ratio.
-
#show_debts_total ⇒ Object
Summarize and show aggregate liabilities totals.
-
#show_equity_total ⇒ Object
Summarize and show aggregate equity totals.
-
#show_net_worth ⇒ Object
Summarize and show Net Worth.
-
#show_quarters ⇒ Object
Summarize and show all financial quarter budgets.
Methods included from BouchCalculate
#calc_assets, #calc_budget_percentage, #calc_debt_ratio, #calc_debt_ratio_percent, #calc_debts, #calc_net_worth, #calc_quarters_raw, #calc_quarters_raw_total, #calc_repeating, #calc_salary
Constructor Details
#initialize(file) ⇒ Bouch
Returns a new instance of Bouch.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/bouch.rb', line 16 def initialize(file) @assets = [] @debts = [] @equity = [] @net_worth = nil @pouch = YAML.safe_load(File.read(file)) raise ArgumentError, 'Invalid or empty YAML file' unless @pouch.is_a?(Hash) @quarters = {} end |
Instance Attribute Details
#assets ⇒ Object
Returns the value of attribute assets.
10 11 12 |
# File 'lib/bouch.rb', line 10 def assets @assets end |
#debts ⇒ Object
Returns the value of attribute debts.
10 11 12 |
# File 'lib/bouch.rb', line 10 def debts @debts end |
#equity ⇒ Object
Returns the value of attribute equity.
10 11 12 |
# File 'lib/bouch.rb', line 10 def equity @equity end |
#net_worth ⇒ Object
Returns the value of attribute net_worth.
10 11 12 |
# File 'lib/bouch.rb', line 10 def net_worth @net_worth end |
#pouch ⇒ Object
Returns the value of attribute pouch.
10 11 12 |
# File 'lib/bouch.rb', line 10 def pouch @pouch end |
#quarters ⇒ Object
Returns the value of attribute quarters.
10 11 12 |
# File 'lib/bouch.rb', line 10 def quarters @quarters end |
Instance Method Details
#show_annual_income ⇒ Object
Summarize and show annual income
109 110 111 112 113 114 |
# File 'lib/bouch.rb', line 109 def show_annual_income label = Paint[format('%-30s', 'Budget Annual Income:'), :magenta] value = Paint[format('%.2f', calc_salary(@pouch['Salary']['quantity'], @pouch['Salary']['frequency'])), :magenta, :bright] puts "#{label} #{value}" end |
#show_annual_total ⇒ Object
Summarize and show the aggregate annual budget totals
88 89 90 91 92 93 |
# File 'lib/bouch.rb', line 88 def show_annual_total calc_quarters_raw(@pouch['Budget']) if @quarters.empty? label = Paint[format('%-30s', 'Budget Annual Total:'), :magenta] value = Paint[format('%.2f', calc_quarters_raw_total), :magenta, :bright] puts "#{label} #{value}" end |
#show_assets_total ⇒ Object
Summarize and show aggregate asset totals
28 29 30 31 32 33 |
# File 'lib/bouch.rb', line 28 def show_assets_total calc_assets(@pouch['Assets'], 'assets') if @assets.empty? label = Paint[format('%-30s', 'Assets Total:'), :green] value = Paint[format('%.2f', @assets.sum), :green, :bright] puts "#{label} #{value}" end |
#show_budget ⇒ Object
Summarize and show all aggregate components of the quarterly, annual budgets, assets
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/bouch.rb', line 117 def show_budget show_quarters show_annual_total puts SEPARATOR puts Paint['INCOME', :magenta, :bold] puts SEPARATOR show_annual_income show_budget_percentage if @pouch['Assets'] || @pouch['Equity'] puts SEPARATOR puts Paint['ASSETS', :green, :bold] puts SEPARATOR show_assets_total if @pouch['Assets'] show_equity_total if @pouch['Equity'] show_net_worth end if @pouch['Debts'] puts SEPARATOR puts Paint['DEBTS', :red, :bold] puts SEPARATOR show_debts_total show_debt_ratio if @net_worth end puts SEPARATOR end |
#show_budget_percentage ⇒ Object
Summarize and show the aggregate annual budget as a percentage of income
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/bouch.rb', line 96 def show_budget_percentage calc_quarters_raw(@pouch['Budget']) if @quarters.empty? label = Paint[format('%-30s', 'Budget Income Percent:'), :magenta] value = Paint[format('%.2f%s', calc_budget_percentage( calc_quarters_raw_total, calc_salary(@pouch['Salary']['quantity'], @pouch['Salary']['frequency']) ), '%'), :magenta, :bright] puts "#{label} #{value}" end |
#show_debt_ratio ⇒ Object
Summarize and show debt ratio
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/bouch.rb', line 44 def show_debt_ratio calc_assets(@pouch['Assets']) if @assets.empty? calc_assets(@pouch['Equity'], 'equity') if @equity.empty? calc_net_worth(@assets, @equity) if @net_worth.nil? calc_debts(@pouch['Debts']) if @debts.empty? ratio = calc_debt_ratio(@debts.sum, @net_worth) label1 = Paint[format('%-30s', 'Debt Ratio:'), :red] value1 = Paint[format('%.4f', ratio), :red, :bright] puts "#{label1} #{value1}" label2 = Paint[format('%-30s', 'Debt Ratio Percent:'), :red] value2 = Paint[format('%.2f%s', calc_debt_ratio_percent(ratio), '%'), :red, :bright] puts "#{label2} #{value2}" end |
#show_debts_total ⇒ Object
Summarize and show aggregate liabilities totals
36 37 38 39 40 41 |
# File 'lib/bouch.rb', line 36 def show_debts_total calc_debts(@pouch['Debts']) if @debts.empty? label = Paint[format('%-30s', 'Debt Total:'), :red] value = Paint[format('%.2f', @debts.sum), :red, :bright] puts "#{label} #{value}" end |
#show_equity_total ⇒ Object
Summarize and show aggregate equity totals
59 60 61 62 63 64 |
# File 'lib/bouch.rb', line 59 def show_equity_total calc_assets(@pouch['Equity'], 'equity') if @equity.empty? label = Paint[format('%-30s', 'Equity Total:'), :green] value = Paint[format('%.2f', @equity.sum), :green, :bright] puts "#{label} #{value}" end |
#show_net_worth ⇒ Object
Summarize and show Net Worth
67 68 69 70 71 72 |
# File 'lib/bouch.rb', line 67 def show_net_worth calc_net_worth(@assets, @equity) if @net_worth.nil? label = Paint[format('%-30s', 'Net Worth:'), :green] value = Paint[format('%.2f', @net_worth), :green, :bright] puts "#{label} #{value}" end |
#show_quarters ⇒ Object
Summarize and show all financial quarter budgets
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/bouch.rb', line 75 def show_quarters calc_quarters_raw(@pouch['Budget']) if @quarters.empty? puts SEPARATOR puts Paint['BUDGET', :magenta, :bold] puts SEPARATOR 4.times do |n| label = Paint[format('%-30s', "Quarter #{n + 1}:"), :magenta] value = Paint[format('%.2f', @quarters[n].sum), :magenta, :bright] puts "#{label} #{value}" end end |