budgetGenerator 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/budgetGenerator.rb +153 -0
  3. metadata +47 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 146218f2b54bd0c47fe9e1453ae02c05aa6004cf
4
+ data.tar.gz: 8f592b0125467d6af57efde6b1e2f5b405270b5f
5
+ SHA512:
6
+ metadata.gz: 40cb25a6ac6678d6e132d8ee5d02b20b9fda9ca04a366e56e35980b6babedb465c8e93f2a76d717dda7cd98b7ba8088f14e2906a02b22892a1e382fd35906d4a
7
+ data.tar.gz: c9c506b35f59832c90e04e719d35acf97832568d10113d83bc91424ce19cf6e9392a112408f8ad973358f219886f327284bdfa1051489cf2e4574baacb67e155
@@ -0,0 +1,153 @@
1
+ #super class defining a Basic Budget class
2
+
3
+ class BasicBudget
4
+ def initialize(amount)
5
+ @amount = amount
6
+ end
7
+
8
+ # getter method for amount
9
+ def amount
10
+ @amount
11
+ end
12
+
13
+ # getter method for savings type: aggressive 20% savings on amount
14
+ def aggressive_savings
15
+ 0.20
16
+ end
17
+
18
+ # getter method for savings type: medium 13% savings on amount
19
+ def medium_savings
20
+ 0.13
21
+ end
22
+
23
+ # getter method for savings type: low 5% savings on amount
24
+ def low_savings
25
+ 0.05
26
+ end
27
+
28
+ # getter method for budget category array
29
+ def budget_category
30
+ @budget_category = ["Home_Rent", "Utilities", "Food_Groceries", "Departmental", "Entertainment", "Car_Auto", "Insurance_Medical", "Misc"]
31
+ end
32
+
33
+ # getter method for budget category percentage
34
+ def budget_category_percentage
35
+ @budget_category_percentage = [0.30, 0.25, 0.15, 0.10, 0.04, 0.06, 0.07, 0.03]
36
+ end
37
+
38
+ #generate budget method
39
+ def generate_budget
40
+ @h = Hash.new
41
+ @budget_category = ["Home_Rent", "Utilities", "Food_Groceries", "Departmental", "Entertainment", "Car_Auto", "Insurance_Medical", "Misc"]
42
+ @budget_category_percentage = [0.30, 0.25, 0.15, 0.10, 0.04, 0.06, 0.07, 0.03]
43
+
44
+ #loop through budget category item and calculate pecentage, then store in a hash
45
+
46
+ @budget_category.each_with_index do |expense_item, expense_index|
47
+ @percentage_for_budget_item = @budget_category_percentage[expense_index]
48
+ @calculated_budget_for_item = @amount.to_f * @percentage_for_budget_item.to_f
49
+ @h.store("#{expense_item}".to_s, @calculated_budget_for_item.to_f.round(2))
50
+ end
51
+
52
+ @h
53
+
54
+ end
55
+
56
+ end
57
+
58
+ #Aggressive savings type decorator class
59
+
60
+ class AggressiveSavings
61
+ def initialize(basic_budget)
62
+ @basic_budget = basic_budget
63
+ end
64
+
65
+ #generate budget method
66
+
67
+ def generate_budget
68
+ @h = Hash.new
69
+
70
+ #deduct aggressive savings percentage from budget amount
71
+
72
+ @aggressive_priority_savings = @basic_budget.aggressive_savings
73
+ @var = @basic_budget.amount.to_f * @aggressive_priority_savings
74
+ @new_amount = @basic_budget.amount.to_f - @var.to_f
75
+ @savings_type_name = 'aggressive'
76
+
77
+ @get_budget_category = @basic_budget.budget_category
78
+ @get_budget_percentage = @basic_budget.budget_category_percentage
79
+
80
+ #loop through budget category item and calculate pecentage, then store in a hash
81
+ @get_budget_category.each_with_index do |expense_item, expense_index|
82
+ @percentage_for_budget_item = @get_budget_percentage[expense_index]
83
+ @calculated_budget_for_item = @new_amount.to_f * @percentage_for_budget_item.to_f
84
+ @h.store("#{expense_item}".to_s, @calculated_budget_for_item.to_f.round(2))
85
+ end
86
+
87
+ @h
88
+ end
89
+ end
90
+
91
+ #Medium savings type decorator class
92
+ class MediumSavings
93
+ def initialize(basic_budget)
94
+ @basic_budget = basic_budget
95
+ end
96
+
97
+ #generate budget method
98
+
99
+ def generate_budget
100
+ @h = Hash.new
101
+
102
+ #deduct medium savings percentage from budget amount
103
+
104
+ @medium_priority_savings = @basic_budget.medium_savings
105
+ @var = @basic_budget.amount.to_f * @medium_priority_savings
106
+ @new_amount = @basic_budget.amount.to_f - @var.to_f
107
+ @savings_type_name = 'medium'
108
+
109
+ @get_budget_category = @basic_budget.budget_category
110
+ @get_budget_percentage = @basic_budget.budget_category_percentage
111
+
112
+ #loop through budget category item and calculate pecentage, then store in a hash
113
+ @get_budget_category.each_with_index do |expense_item, expense_index|
114
+ @percentage_for_budget_item = @get_budget_percentage[expense_index]
115
+ @calculated_budget_for_item = @new_amount.to_f * @percentage_for_budget_item.to_f
116
+ @h.store("#{expense_item}".to_s, @calculated_budget_for_item.to_f.round(2))
117
+ end
118
+
119
+ @h
120
+ end
121
+ end
122
+
123
+ #Low savings type decorator class
124
+ class LowSavings
125
+ def initialize(basic_budget)
126
+ @basic_budget = basic_budget
127
+ end
128
+
129
+ #generate budget method
130
+
131
+ def generate_budget
132
+ @h = Hash.new
133
+
134
+ #deduct low savings percentage from budget amount
135
+
136
+ @low_priority_savings = @basic_budget.low_savings
137
+ @var = @basic_budget.amount.to_f * @low_priority_savings
138
+ @new_amount = @basic_budget.amount.to_f - @var.to_f
139
+ @savings_type_name = 'low'
140
+
141
+ @get_budget_category = @basic_budget.budget_category
142
+ @get_budget_percentage = @basic_budget.budget_category_percentage
143
+
144
+ #loop through budget category item and calculate pecentage, then store in a hash
145
+ @get_budget_category.each_with_index do |expense_item, expense_index|
146
+ @percentage_for_budget_item = @get_budget_percentage[expense_index]
147
+ @calculated_budget_for_item = @new_amount.to_f * @percentage_for_budget_item.to_f
148
+ @h.store("#{expense_item}".to_s, @calculated_budget_for_item.to_f.round(2))
149
+ end
150
+
151
+ @h
152
+ end
153
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: budgetGenerator
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - weje praise
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-04-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 'Budget generator gem allows users make smart monthly savings according
14
+ to three different types of savings mode: Aggressive, medium and low. This generates
15
+ a hash that can be used to build a budget feature within an application. Created
16
+ by weje praise, 2019'
17
+ email: wejepraise@yahoo.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - lib/budgetGenerator.rb
23
+ homepage: http://github.com/wejeel/budget-generator
24
+ licenses: []
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.6.8
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: This is a budget generator gem. It was built to help people plan their finances
46
+ with the most common expenses.
47
+ test_files: []