banco 1.0.2 → 1.0.3
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.
- checksums.yaml +4 -4
- data/bin/banco +43 -40
- data/lib/banco/get_file.rb +36 -34
- data/lib/banco/reader.rb +51 -54
- data/lib/banco/reporter.rb +57 -59
- data/lib/banco/transaction.rb +25 -24
- data/lib/banco/viewable.rb +70 -69
- data/spec/banco/reader_spec.rb +13 -11
- data/spec/banco/reporter_spec.rb +52 -51
- data/spec/banco/transaction_spec.rb +45 -43
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ce7ba84a2102c4036382a535b0da7a40ea8d0e5230ecb5bed701f63ae823febd
|
|
4
|
+
data.tar.gz: 03fd4cd2808134359200dd681f9b1c6905f0aa86c9c0c3e96a5407ab7aaa8839
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d0155da256d6bd565971b345a5c0ee55cf6af5f141edd348869698f58c75f781260952ae59663b84896b65c584484abdd4cc855c2bfdca681b17620a80ebd70c
|
|
7
|
+
data.tar.gz: e22296a81318c9b612de090e568991e80967ff834ae51255a0541ddf175910468b87333e2fc93643b6feb9c9c42fdea1caac910727a7a3850a143c8e47e4487e
|
data/bin/banco
CHANGED
|
@@ -6,45 +6,48 @@ require_relative '../lib/banco/reader'
|
|
|
6
6
|
require_relative '../lib/banco/reporter'
|
|
7
7
|
|
|
8
8
|
module Banco
|
|
9
|
+
def self.starter
|
|
10
|
+
Viewable::prompt
|
|
11
|
+
begin
|
|
12
|
+
file = GetFile.new
|
|
13
|
+
reader = Reader.new(file.csv_file_name, file.summary_name)
|
|
14
|
+
reader.read_in_csv_data
|
|
15
|
+
Reporter.new(reader.csv_file_name, reader.report_name, reader.all_from_csv)
|
|
16
|
+
rescue
|
|
17
|
+
puts "try again or 'q' to exit".center(54)
|
|
18
|
+
retry
|
|
19
|
+
end
|
|
20
|
+
end
|
|
9
21
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
report.save_transactions_to_file
|
|
42
|
-
when "q"
|
|
43
|
-
break
|
|
44
|
-
else
|
|
45
|
-
report.menu
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
Viewable::farewell
|
|
22
|
+
Viewable::hello
|
|
23
|
+
report = starter
|
|
24
|
+
loop do
|
|
25
|
+
report.menu
|
|
26
|
+
answer = gets.chomp.downcase
|
|
27
|
+
case answer
|
|
28
|
+
when 'a'
|
|
29
|
+
print report.transactions_all
|
|
30
|
+
when 'o'
|
|
31
|
+
print report.transactions_out
|
|
32
|
+
when 'i'
|
|
33
|
+
print report.transactions_in
|
|
34
|
+
when 'm'
|
|
35
|
+
print report.money_out_summary
|
|
36
|
+
when 'n'
|
|
37
|
+
print report.money_in_summary
|
|
38
|
+
when 'b'
|
|
39
|
+
print report.bottom_line
|
|
40
|
+
when 'l'
|
|
41
|
+
report = starter
|
|
42
|
+
when 's'
|
|
43
|
+
report.save_summary_to_file
|
|
44
|
+
when 't'
|
|
45
|
+
report.save_transactions_to_file
|
|
46
|
+
when 'q'
|
|
47
|
+
break
|
|
48
|
+
else
|
|
49
|
+
report.menu
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
Viewable::farewell
|
|
49
53
|
end
|
|
50
|
-
|
data/lib/banco/get_file.rb
CHANGED
|
@@ -1,41 +1,43 @@
|
|
|
1
|
+
|
|
1
2
|
module Banco
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
class GetFile
|
|
4
|
+
attr_reader :name, :csv_file_name, :summary_name
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
end
|
|
17
|
-
end
|
|
6
|
+
def initialize
|
|
7
|
+
@csv_file_name = gets.chomp.downcase
|
|
8
|
+
if @csv_file_name == 'q'
|
|
9
|
+
Viewable::farewell
|
|
10
|
+
exit
|
|
11
|
+
else
|
|
12
|
+
file_checker_cleaner(@csv_file_name)
|
|
13
|
+
@name = @csv_file_name.split('.').first
|
|
14
|
+
make_name
|
|
15
|
+
end
|
|
16
|
+
end
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
make_name
|
|
26
|
-
end
|
|
27
|
-
end
|
|
18
|
+
def make_name
|
|
19
|
+
@name = @csv_file_name.split('.').first
|
|
20
|
+
@doctype = @csv_file_name.split('.').last
|
|
21
|
+
@summary_name = @name
|
|
22
|
+
@csv_file_name
|
|
23
|
+
end
|
|
28
24
|
|
|
29
|
-
|
|
25
|
+
def file_checker_cleaner(filename)
|
|
26
|
+
if filename =~ /([^\s]+(\.csv)$)/
|
|
27
|
+
puts "\nloading #{filename}..."
|
|
28
|
+
else
|
|
29
|
+
puts "#{filename} isn't a valid file for Banco !".center(54)
|
|
30
|
+
throw
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
30
34
|
end
|
|
31
35
|
|
|
32
|
-
if
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
if $PROGRAM_NAME == __FILE__
|
|
37
|
+
file = Banco::GetFile.new
|
|
38
|
+
file.make_name
|
|
39
|
+
puts "\n\n\n"
|
|
40
|
+
p file.valid_file
|
|
41
|
+
p file.name
|
|
42
|
+
p file.summary_name
|
|
39
43
|
end
|
|
40
|
-
|
|
41
|
-
|
data/lib/banco/reader.rb
CHANGED
|
@@ -1,67 +1,64 @@
|
|
|
1
|
+
|
|
1
2
|
require_relative 'transaction'
|
|
2
3
|
require_relative 'viewable'
|
|
3
4
|
require 'csv'
|
|
4
5
|
|
|
5
6
|
module Banco
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
attr_reader :all_from_csv, :report_name, :csv_file_name
|
|
10
|
-
|
|
11
|
-
def initialize(csv_file_name, report_name)
|
|
12
|
-
@csv_file_name = csv_file_name
|
|
13
|
-
@report_name = report_name
|
|
14
|
-
@all_from_csv = []
|
|
15
|
-
end
|
|
7
|
+
class Reader
|
|
8
|
+
include Viewable
|
|
16
9
|
|
|
17
|
-
|
|
18
|
-
begin
|
|
19
|
-
@csv_row_count = 1
|
|
10
|
+
attr_reader :all_from_csv, :report_name, :csv_file_name
|
|
20
11
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
12
|
+
def initialize(csv_file_name, report_name)
|
|
13
|
+
@csv_file_name = csv_file_name
|
|
14
|
+
@report_name = report_name
|
|
15
|
+
@all_from_csv = []
|
|
16
|
+
end
|
|
25
17
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
puts "sorted ? ('y' to continue or 'q' to exit)".rjust(54)
|
|
29
|
-
input = gets.chomp.downcase
|
|
30
|
-
@all_from_csv = []
|
|
31
|
-
input == "y" ? retry : Viewable::farewell
|
|
18
|
+
def read_in_csv_data
|
|
19
|
+
@csv_row_count = 1
|
|
32
20
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
puts "
|
|
21
|
+
CSV.foreach(csv_file_name) do |row|
|
|
22
|
+
all_from_csv << Transaction.new(row[0], row[1], row[2], row[3], row[4], @csv_row_count)
|
|
23
|
+
@csv_row_count += 1
|
|
24
|
+
end
|
|
25
|
+
rescue ArgumentError => e
|
|
26
|
+
non_numeric_in_csv(e, @csv_row_count)
|
|
27
|
+
puts "sorted ? ('y' to continue or 'q' to exit)".rjust(54)
|
|
28
|
+
input = gets.chomp.downcase
|
|
29
|
+
@all_from_csv = []
|
|
30
|
+
input == 'y' ? retry : Viewable.farewell
|
|
31
|
+
rescue Errno::ENOENT => e
|
|
32
|
+
puts "Can't find file #{@csv_file_name} - have another go or (q) quit\n\n"
|
|
33
|
+
loop do
|
|
34
|
+
input = gets.chomp.downcase
|
|
35
|
+
case input
|
|
36
|
+
when 'q'
|
|
37
|
+
Viewable.farewell
|
|
38
|
+
exit
|
|
39
|
+
when /([^\s]+(\.csv)$)/
|
|
40
|
+
@csv_file_name = input
|
|
41
|
+
break
|
|
42
|
+
else
|
|
43
|
+
puts "\ninvalid file - try again or 'q' to quit\n\n"
|
|
44
|
+
end
|
|
56
45
|
end
|
|
57
|
-
|
|
46
|
+
retry
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def non_numeric_in_csv(exception, row_number)
|
|
50
|
+
reason = exception.message.split(':')
|
|
51
|
+
puts "Please check row #{row_number} of #{@csv_file_name},"
|
|
52
|
+
puts "#{reason.last} should be a numeric value".rjust(54)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
58
55
|
end
|
|
59
56
|
|
|
60
|
-
if
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
57
|
+
if $PROGRAM_NAME == __FILE__
|
|
58
|
+
reader = Banco::Reader.new('test.csv', 'test')
|
|
59
|
+
reader.read_in_csv_data
|
|
60
|
+
puts reader.report_name
|
|
61
|
+
puts reader.csv_file_name
|
|
62
|
+
puts reader.all_from_csv
|
|
63
|
+
p reader
|
|
67
64
|
end
|
data/lib/banco/reporter.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
require_relative 'transaction'
|
|
2
3
|
require_relative 'reader'
|
|
3
4
|
require_relative 'viewable'
|
|
@@ -5,72 +6,69 @@ require 'csv'
|
|
|
5
6
|
|
|
6
7
|
module Banco
|
|
7
8
|
class Reporter
|
|
8
|
-
|
|
9
9
|
include Viewable
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
36
|
|
|
37
|
+
def remove_blank_lines
|
|
38
|
+
@all_transactions.delete_if { |trans| trans.moneyin.zero? && trans.moneyout.zero? }
|
|
39
|
+
end
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
def split_in_out
|
|
42
|
+
@outgoing_trans, @incoming_trans = @all_transactions.partition { |trans| trans.moneyin.zero? && trans.moneyout.positive? }
|
|
43
|
+
end
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
|
|
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
|
|
45
49
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def total_incoming
|
|
52
|
-
@incoming_trans.each{|trans| @incomings[trans.description[0..8]] += trans.moneyin}
|
|
53
|
-
@incoming_total = @incomings.values.map.reduce(:+)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
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
|
|
56
55
|
end
|
|
57
56
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
p report.incomings
|
|
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
|
|
76
74
|
end
|
data/lib/banco/transaction.rb
CHANGED
|
@@ -1,31 +1,32 @@
|
|
|
1
|
+
|
|
1
2
|
module Banco
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
class Transaction
|
|
4
|
+
require 'bigdecimal'
|
|
5
|
+
attr_reader :date, :description, :type, :moneyin, :moneyout, :csv_row_count
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
def initialize(date_string, description, type, moneyin, moneyout, csv_row_count)
|
|
8
|
+
@csv_row_count = csv_row_count
|
|
9
|
+
@moneyin = convert(moneyin)
|
|
10
|
+
@moneyout = convert(moneyout)
|
|
11
|
+
@date = date_string
|
|
12
|
+
@description = format('%-22.22s', description.upcase.to_s)
|
|
13
|
+
@type = format('%-8.8s', type.upcase.to_s)
|
|
14
|
+
end
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
def convert(money)
|
|
17
|
+
money.nil? ? BigDecimal('0') : BigDecimal(money)
|
|
18
|
+
end
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
def to_s
|
|
21
|
+
"#{date} #{type} #{description}"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
23
24
|
end
|
|
24
25
|
|
|
25
|
-
if
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
if $PROGRAM_NAME == __FILE__
|
|
27
|
+
trans = Banco::Transaction.new('01/01/17', 'Supermarket', 'Purchase', '72.90', '0', '1')
|
|
28
|
+
p trans
|
|
29
|
+
t = Banco::Transaction.new
|
|
30
|
+
t.send(:initialize, '02/02/18', 'new way', 'credit', '0', '111.11', '2')
|
|
31
|
+
p t
|
|
31
32
|
end
|
data/lib/banco/viewable.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
module Banco
|
|
2
3
|
module Viewable
|
|
3
4
|
def menu
|
|
@@ -15,16 +16,16 @@ module Banco
|
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
def to_pounds(money)
|
|
18
|
-
format =
|
|
19
|
+
format = format('%10.2f', money.truncate(2))
|
|
19
20
|
"£#{format}"
|
|
20
21
|
end
|
|
21
22
|
|
|
22
23
|
def dashes
|
|
23
|
-
|
|
24
|
+
'---'.center(55, '-')
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
def date_range
|
|
27
|
-
"(#{
|
|
28
|
+
"(#{all_transactions.last.date} - #{all_transactions.first.date})"
|
|
28
29
|
end
|
|
29
30
|
|
|
30
31
|
def facts(transactions)
|
|
@@ -32,59 +33,59 @@ module Banco
|
|
|
32
33
|
end
|
|
33
34
|
|
|
34
35
|
def money_out_summary
|
|
35
|
-
print_summary(
|
|
36
|
+
print_summary('Outgoings', outgoings, outgoing_total)
|
|
36
37
|
end
|
|
37
38
|
|
|
38
39
|
def money_in_summary
|
|
39
|
-
print_summary(
|
|
40
|
+
print_summary('Incomings', incomings, incoming_total)
|
|
40
41
|
end
|
|
41
42
|
|
|
42
43
|
def transactions_all
|
|
43
|
-
output =
|
|
44
|
+
output = ''
|
|
44
45
|
output << dashes
|
|
45
46
|
output << "\n"
|
|
46
47
|
output << "All transactions:\n"
|
|
47
|
-
output << "#{facts(
|
|
48
|
-
|
|
49
|
-
if trans.moneyout == 0
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
|
54
55
|
end
|
|
55
56
|
output << dashes
|
|
56
57
|
output << "\n\n"
|
|
57
58
|
end
|
|
58
59
|
|
|
59
60
|
def transactions_out
|
|
60
|
-
output =
|
|
61
|
+
output = ''
|
|
61
62
|
output << dashes
|
|
62
63
|
output << "\n"
|
|
63
64
|
output << "Outgoing Transactions:\n"
|
|
64
|
-
output << "#{facts(
|
|
65
|
-
|
|
65
|
+
output << "#{facts(outgoing_trans)}\n\n"
|
|
66
|
+
outgoing_trans.each { |trans| output << "#{trans} - #{to_pounds(trans.moneyout)}\n" }
|
|
66
67
|
output << dashes
|
|
67
68
|
output << "\n\n"
|
|
68
69
|
end
|
|
69
70
|
|
|
70
71
|
def transactions_in
|
|
71
|
-
output =
|
|
72
|
+
output = ''
|
|
72
73
|
output << dashes
|
|
73
74
|
output << "\n"
|
|
74
75
|
output << "Incoming Transactions :\n"
|
|
75
|
-
output << "#{facts(
|
|
76
|
-
|
|
76
|
+
output << "#{facts(incoming_trans)}\n\n"
|
|
77
|
+
incoming_trans.each { |trans| output << "#{trans} + #{to_pounds(trans.moneyin)}\n" }
|
|
77
78
|
output << dashes
|
|
78
79
|
output << "\n\n"
|
|
79
80
|
end
|
|
80
81
|
|
|
81
82
|
def print_summary(kind, hash, total)
|
|
82
|
-
output =
|
|
83
|
+
output = ''
|
|
83
84
|
output << dashes
|
|
84
85
|
output << "\n"
|
|
85
86
|
output << "#{kind} Summary, totals from #{hash.size} different sources :\n"
|
|
86
87
|
output << "#{date_range}\n"
|
|
87
|
-
hash.sort_by{|_k,v| v}.reverse.each{|k,v| output << "#{k} #{to_pounds(v)}\n".rjust(54)}
|
|
88
|
+
hash.sort_by { |_k, v| v }.reverse.each { |k, v| output << "#{k} #{to_pounds(v)}\n".rjust(54) }
|
|
88
89
|
output << "\n"
|
|
89
90
|
output << "Total #{kind}: #{to_pounds(total)}\n".rjust(54)
|
|
90
91
|
output << dashes
|
|
@@ -92,21 +93,21 @@ module Banco
|
|
|
92
93
|
end
|
|
93
94
|
|
|
94
95
|
def bottom_line
|
|
95
|
-
output =
|
|
96
|
+
output = ''
|
|
96
97
|
output << dashes
|
|
97
98
|
output << "\n"
|
|
98
|
-
output <<
|
|
99
|
+
output << facts(all_transactions).to_s.rjust(54)
|
|
99
100
|
output << "\n\n"
|
|
100
|
-
output << "Money In : #{to_pounds(
|
|
101
|
+
output << "Money In : #{to_pounds(incoming_total)}".rjust(54)
|
|
101
102
|
output << "\n"
|
|
102
|
-
output << "Money Out : #{to_pounds(
|
|
103
|
+
output << "Money Out : #{to_pounds(outgoing_total)}".rjust(54)
|
|
103
104
|
output << "\n\n"
|
|
104
|
-
diff =
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
|
110
111
|
output << "\n"
|
|
111
112
|
output << dashes
|
|
112
113
|
output << "\n\n"
|
|
@@ -114,67 +115,67 @@ module Banco
|
|
|
114
115
|
|
|
115
116
|
def self.farewell
|
|
116
117
|
puts "\n\n"
|
|
117
|
-
puts
|
|
118
|
-
puts
|
|
119
|
-
puts
|
|
120
|
-
puts
|
|
121
|
-
puts
|
|
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, '*')
|
|
122
123
|
puts "\n\n\n"
|
|
123
124
|
exit
|
|
124
125
|
end
|
|
125
126
|
|
|
126
127
|
def self.hello
|
|
127
128
|
puts "\n\n"
|
|
128
|
-
puts
|
|
129
|
-
puts
|
|
129
|
+
puts 'Banco will summarize your bank statements.'.center(55)
|
|
130
|
+
puts 'import a .csv file for review'.center(55)
|
|
130
131
|
puts "\n\n"
|
|
131
|
-
puts
|
|
132
|
-
puts
|
|
133
|
-
puts
|
|
134
|
-
puts
|
|
135
|
-
puts
|
|
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)
|
|
136
137
|
end
|
|
137
138
|
|
|
138
139
|
def self.prompt
|
|
139
140
|
puts "\n\n"
|
|
140
|
-
puts
|
|
141
|
+
puts 'Enter the name of you .csv file to review'.center(54)
|
|
141
142
|
puts "(use 'test.csv' for the test file)".center(54)
|
|
142
143
|
puts "or 'q' to quit...".center(55)
|
|
143
144
|
puts "\n\n"
|
|
144
145
|
end
|
|
145
146
|
|
|
146
|
-
def save_summary_to_file(to_file="#{
|
|
147
|
-
File.open(to_file,
|
|
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|
|
|
148
166
|
t = Time.now
|
|
149
167
|
file.puts t.strftime("\n\nprinted : %d %b %y at %I:%M%P")
|
|
150
|
-
file.puts "summarized by Banco from #{
|
|
168
|
+
file.puts "summarized by Banco from #{csv_file_name}"
|
|
151
169
|
file.puts "\n"
|
|
152
|
-
file.puts
|
|
170
|
+
file.puts transactions_out
|
|
153
171
|
file.puts "\n"
|
|
154
|
-
file.puts
|
|
172
|
+
file.puts transactions_in
|
|
155
173
|
file.puts "\n"
|
|
156
|
-
file.puts
|
|
174
|
+
file.puts bottom_line
|
|
157
175
|
file.puts "\n"
|
|
158
|
-
file.puts
|
|
176
|
+
file.puts '♥️ code@s33d.co'.rjust(54)
|
|
159
177
|
end
|
|
160
|
-
puts "\n\nfile saved as #{
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
def save_transactions_to_file(to_file="#{self.name}_transactions.txt")
|
|
164
|
-
File.open(to_file, "w") do |file|
|
|
165
|
-
t = Time.now
|
|
166
|
-
file.puts t.strftime("\n\nprinted : %d %b %y at %I:%M%P")
|
|
167
|
-
file.puts "summarized by Banco from #{self.csv_file_name}"
|
|
168
|
-
file.puts "\n"
|
|
169
|
-
file.puts self.transactions_out
|
|
170
|
-
file.puts "\n"
|
|
171
|
-
file.puts self.transactions_in
|
|
172
|
-
file.puts "\n"
|
|
173
|
-
file.puts self.bottom_line
|
|
174
|
-
file.puts "\n"
|
|
175
|
-
file.puts "code@s33d.co".rjust(54)
|
|
176
|
-
end
|
|
177
|
-
puts "\n\nfile saved as #{self.name}_transactions.txt\n\n"
|
|
178
|
+
puts "\n\nfile saved as #{name}_transactions.txt\n\n"
|
|
178
179
|
end
|
|
179
180
|
end
|
|
180
181
|
end
|
data/spec/banco/reader_spec.rb
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'banco/reader'
|
|
2
4
|
module Banco
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
14
16
|
end
|
data/spec/banco/reporter_spec.rb
CHANGED
|
@@ -1,54 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'banco/reporter'
|
|
2
4
|
require 'banco/reader'
|
|
3
5
|
module Banco
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
end
|
|
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,47 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'banco/transaction'
|
|
2
4
|
|
|
3
5
|
module Banco
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
|
47
49
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: banco
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- s33d
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-
|
|
11
|
+
date: 2019-11-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|