banco 1.0.3 → 2.0.1

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.
@@ -1,74 +0,0 @@
1
-
2
- require_relative 'transaction'
3
- require_relative 'reader'
4
- require_relative 'viewable'
5
- require 'csv'
6
-
7
- module Banco
8
- class Reporter
9
- include Viewable
10
-
11
- attr_reader :all_transactions,
12
- :outgoing_trans,
13
- :incoming_trans,
14
- :outgoings,
15
- :incomings,
16
- :outgoing_total,
17
- :incoming_total,
18
- :name,
19
- :csv_file_name
20
-
21
- def initialize(csv_file_name, report_name, transactions)
22
- @csv_file_name = csv_file_name
23
- @name = report_name
24
- @all_transactions = transactions
25
- @outgoing_trans = []
26
- @incoming_trans = []
27
- @outgoings = Hash.new(0)
28
- @incomings = Hash.new(0)
29
- puts 'formating data...'
30
- remove_blank_lines
31
- split_in_out
32
- total_outgoing
33
- total_incoming
34
- puts "\n\n"
35
- end
36
-
37
- def remove_blank_lines
38
- @all_transactions.delete_if { |trans| trans.moneyin.zero? && trans.moneyout.zero? }
39
- end
40
-
41
- def split_in_out
42
- @outgoing_trans, @incoming_trans = @all_transactions.partition { |trans| trans.moneyin.zero? && trans.moneyout.positive? }
43
- end
44
-
45
- def total_outgoing
46
- @outgoing_trans.each { |trans| @outgoings[trans.description[0..8]] += trans.moneyout }
47
- @outgoing_total = @outgoings.values.map.reduce(:+)
48
- end
49
-
50
- def total_incoming
51
- @incoming_trans.each { |trans| @incomings[trans.description[0..8]] += trans.moneyin }
52
- @incoming_total = @incomings.values.map.reduce(:+)
53
- end
54
- end
55
- end
56
-
57
- if $PROGRAM_NAME == __FILE__
58
- reader = Banco::Reader.new('test.csv', 'test')
59
- reader.read_in_csv_data
60
- puts "\n\n\n#all csv data from reader object\n\n"
61
- puts "#{reader.all_from_csv}\n\n"
62
- report = Banco::Reporter.new(reader.csv_file_name, reader.report_name, reader.all_from_csv)
63
- puts "#{report.name} is the Reporter object's name\nReporter object contents below, (3 arrays, 2 hashes):\n\n"
64
- puts "\n\nall transactions array\n"
65
- p report.all_transactions
66
- puts "\n\noutgoings array\n"
67
- p report.outgoing_trans
68
- puts "\n\nincomings array\n"
69
- p report.incoming_trans
70
- puts "\n\nOutgoings hash\n"
71
- p report.outgoings
72
- puts "\n\nIncomings hash\n"
73
- p report.incomings
74
- end
@@ -1,181 +0,0 @@
1
-
2
- module Banco
3
- module Viewable
4
- def menu
5
- puts "Enter :\n"
6
- puts "'a' to view all transactions"
7
- puts "'o' to view all outgoing transactions"
8
- puts "'i' to view all incoming transactions"
9
- puts "'m' for money out summary"
10
- puts "'n' for money in summary"
11
- puts "'b' for the bottom line"
12
- puts "'s' to save summaries to file"
13
- puts "'t' to save transactions to file"
14
- puts "\n'l' to load a new file\n"
15
- puts "\nor 'q' to quit\n\n\n"
16
- end
17
-
18
- def to_pounds(money)
19
- format = format('%10.2f', money.truncate(2))
20
- "£#{format}"
21
- end
22
-
23
- def dashes
24
- '---'.center(55, '-')
25
- end
26
-
27
- def date_range
28
- "(#{all_transactions.last.date} - #{all_transactions.first.date})"
29
- end
30
-
31
- def facts(transactions)
32
- "#{transactions.size} transactions for period #{date_range}"
33
- end
34
-
35
- def money_out_summary
36
- print_summary('Outgoings', outgoings, outgoing_total)
37
- end
38
-
39
- def money_in_summary
40
- print_summary('Incomings', incomings, incoming_total)
41
- end
42
-
43
- def transactions_all
44
- output = ''
45
- output << dashes
46
- output << "\n"
47
- output << "All transactions:\n"
48
- output << "#{facts(all_transactions)}\n\n"
49
- all_transactions.each do |trans|
50
- output << if trans.moneyout == 0
51
- "#{trans} + #{to_pounds(trans.moneyin)}\n"
52
- else
53
- "#{trans} - #{to_pounds(trans.moneyout)}\n"
54
- end
55
- end
56
- output << dashes
57
- output << "\n\n"
58
- end
59
-
60
- def transactions_out
61
- output = ''
62
- output << dashes
63
- output << "\n"
64
- output << "Outgoing Transactions:\n"
65
- output << "#{facts(outgoing_trans)}\n\n"
66
- outgoing_trans.each { |trans| output << "#{trans} - #{to_pounds(trans.moneyout)}\n" }
67
- output << dashes
68
- output << "\n\n"
69
- end
70
-
71
- def transactions_in
72
- output = ''
73
- output << dashes
74
- output << "\n"
75
- output << "Incoming Transactions :\n"
76
- output << "#{facts(incoming_trans)}\n\n"
77
- incoming_trans.each { |trans| output << "#{trans} + #{to_pounds(trans.moneyin)}\n" }
78
- output << dashes
79
- output << "\n\n"
80
- end
81
-
82
- def print_summary(kind, hash, total)
83
- output = ''
84
- output << dashes
85
- output << "\n"
86
- output << "#{kind} Summary, totals from #{hash.size} different sources :\n"
87
- output << "#{date_range}\n"
88
- hash.sort_by { |_k, v| v }.reverse.each { |k, v| output << "#{k} #{to_pounds(v)}\n".rjust(54) }
89
- output << "\n"
90
- output << "Total #{kind}: #{to_pounds(total)}\n".rjust(54)
91
- output << dashes
92
- output << "\n\n"
93
- end
94
-
95
- def bottom_line
96
- output = ''
97
- output << dashes
98
- output << "\n"
99
- output << facts(all_transactions).to_s.rjust(54)
100
- output << "\n\n"
101
- output << "Money In : #{to_pounds(incoming_total)}".rjust(54)
102
- output << "\n"
103
- output << "Money Out : #{to_pounds(outgoing_total)}".rjust(54)
104
- output << "\n\n"
105
- diff = incoming_total - outgoing_total
106
- output << if outgoing_total > incoming_total
107
- "Outgoings exceed Incomings, DEFICIT of #{to_pounds(diff)}".rjust(54)
108
- else
109
- "Incomings exceed Outgoings, SURPLUS of #{to_pounds(diff)}".rjust(54)
110
- end
111
- output << "\n"
112
- output << dashes
113
- output << "\n\n"
114
- end
115
-
116
- def self.farewell
117
- puts "\n\n"
118
- puts '*'.center(55, '*')
119
- puts ' Banco '.center(55, '*')
120
- puts ' hope your numbers were positive '.center(55, '*')
121
- puts ' ♥️ code@s33d.co '.center(56, '*')
122
- puts '*'.center(55, '*')
123
- puts "\n\n\n"
124
- exit
125
- end
126
-
127
- def self.hello
128
- puts "\n\n"
129
- puts 'Banco will summarize your bank statements.'.center(55)
130
- puts 'import a .csv file for review'.center(55)
131
- puts "\n\n"
132
- puts 'the .csv file should have :'.center(55)
133
- puts 'NO headers'.center(55)
134
- puts 'with columns ordered (left to right)'.center(55)
135
- puts 'date - description - type - money in - money out'.center(55)
136
- puts 'all additional columns will be ignored'.center(55)
137
- end
138
-
139
- def self.prompt
140
- puts "\n\n"
141
- puts 'Enter the name of you .csv file to review'.center(54)
142
- puts "(use 'test.csv' for the test file)".center(54)
143
- puts "or 'q' to quit...".center(55)
144
- puts "\n\n"
145
- end
146
-
147
- def save_summary_to_file(to_file = "#{name}_summary.txt")
148
- File.open(to_file, 'w') do |file|
149
- t = Time.now
150
- file.puts t.strftime("\n\nprinted : %d %b %y at %I:%M%P")
151
- file.puts "summarized by Banco from #{csv_file_name}"
152
- file.puts "\n"
153
- file.puts money_out_summary
154
- file.puts "\n"
155
- file.puts money_in_summary
156
- file.puts "\n"
157
- file.puts bottom_line
158
- file.puts "\n"
159
- file.puts '♥️ code@s33d.co'.rjust(54)
160
- end
161
- puts "\n\nfile saved as #{name}_summary.txt\n\n"
162
- end
163
-
164
- def save_transactions_to_file(to_file = "#{name}_transactions.txt")
165
- File.open(to_file, 'w') do |file|
166
- t = Time.now
167
- file.puts t.strftime("\n\nprinted : %d %b %y at %I:%M%P")
168
- file.puts "summarized by Banco from #{csv_file_name}"
169
- file.puts "\n"
170
- file.puts transactions_out
171
- file.puts "\n"
172
- file.puts transactions_in
173
- file.puts "\n"
174
- file.puts bottom_line
175
- file.puts "\n"
176
- file.puts '♥️ code@s33d.co'.rjust(54)
177
- end
178
- puts "\n\nfile saved as #{name}_transactions.txt\n\n"
179
- end
180
- end
181
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'banco/reader'
4
- module Banco
5
- describe Reader do
6
- before do
7
- csv_file_name = 'test.csv'
8
- report_name = 'test'
9
- @testreader = Banco::Reader.new(csv_file_name, report_name)
10
- @testreader.read_in_csv_data
11
- end
12
- it 'should produce an array for all rows on csv file' do
13
- expect(@testreader.all_from_csv.length).to eq(10)
14
- end
15
- end
16
- end
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'banco/reporter'
4
- require 'banco/reader'
5
- module Banco
6
- describe Reporter do
7
- before do
8
- csv_file_name = 'test.csv'
9
- report_name = 'test'
10
- @testreader = Banco::Reader.new(csv_file_name, report_name)
11
- @testreader.read_in_csv_data
12
- @tester = Banco::Reporter.new('test.csv', 'test', @testreader.all_from_csv)
13
- @tester.remove_blank_lines
14
- @tester.split_in_out
15
- @tester.total_outgoing
16
- @tester.total_incoming
17
- end
18
-
19
- it 'should remove transactions with zero values (moneyin / moneyout)' do
20
- expect(@tester.all_transactions.size).to eq(8)
21
- end
22
-
23
- it 'should produce an array of incoming transactions' do
24
- expect(@tester.incoming_trans.size).to eq(4)
25
- end
26
-
27
- it 'should produce an array of outgoing transactions' do
28
- expect(@tester.outgoing_trans.size).to eq(4)
29
- end
30
-
31
- it 'should produce a hash of outgoing transactions' do
32
- expect(@tester.outgoings.size).to eq(2)
33
- end
34
-
35
- it 'should produce a hash of incoming transactions' do
36
- expect(@tester.incomings.size).to eq(2)
37
- end
38
-
39
- it 'should sum incoming transactions by matching description string' do
40
- expect(@tester.incomings['INCOMING2']).to eq(183.34)
41
- end
42
-
43
- it 'should sum outgoing transactions by matching description string' do
44
- expect(@tester.outgoings['OUTGOING2']).to eq(182.68)
45
- end
46
-
47
- it 'should sum total incoming transactions' do
48
- expect(@tester.incoming_total).to eq(321.58)
49
- end
50
-
51
- it 'should sum total outgoing transactions' do
52
- expect(@tester.outgoing_total).to eq(320.92)
53
- end
54
- end
55
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'banco/transaction'
4
-
5
- module Banco
6
- describe Transaction do
7
- before do
8
- @trans1 = Transaction.new('12/01/17', 'some transaction', 'credit', '57.91', '0.00', '1')
9
- @trans2 = Transaction.new('13/01/17', 'some other transaction', 'debit', '0.00', '57.91', '2')
10
- end
11
-
12
- # it "Should convert money in values to pence" do
13
- # expect(@trans1.moneyin).to eq(5791)
14
- # end
15
-
16
- # it "Should convert money out values to pence" do
17
- # expect(@trans2.moneyout).to eq(5791)
18
- # end
19
-
20
- it 'Should have a description string of 22 characters (upcase)' do
21
- expect(@trans2.description).to eq('SOME OTHER TRANSACTION')
22
- expect(@trans1.description).to eq('SOME TRANSACTION ')
23
- end
24
-
25
- it 'Should have a type string upcased and 8 characters long' do
26
- expect(@trans2.type).to eq('DEBIT ')
27
- end
28
-
29
- it 'Should have a date string' do
30
- expect(@trans1.date).to eq('12/01/17')
31
- end
32
-
33
- it 'Should have a row number' do
34
- expect(@trans2.csv_row_count).to eq('2')
35
- end
36
-
37
- it 'should have a to_s of all date description type' do
38
- expect(@trans1.to_s).to eq('12/01/17 CREDIT SOME TRANSACTION ')
39
- end
40
-
41
- it 'convert empty strings in money columns to integers' do
42
- expect(@trans1.moneyout).to eq(0)
43
- end
44
-
45
- it 'convert empty strings in money columns to integers' do
46
- expect(@trans2.moneyin).to eq(0)
47
- end
48
- end
49
- end