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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +45 -0
- data/README.md +141 -0
- data/bin/banco +95 -44
- data/lib/banco/bank_format.rb +67 -0
- data/lib/banco/cli.rb +92 -0
- data/lib/banco/file_picker.rb +45 -0
- data/lib/banco/formatter/base.rb +37 -0
- data/lib/banco/formatter/csv_formatter.rb +21 -0
- data/lib/banco/formatter/json_formatter.rb +29 -0
- data/lib/banco/formatter/text.rb +143 -0
- data/lib/banco/grouper.rb +50 -0
- data/lib/banco/parser.rb +39 -0
- data/lib/banco/report.rb +10 -0
- data/lib/banco/transaction.rb +46 -25
- data/lib/banco/version.rb +5 -0
- data/lib/banco.rb +17 -0
- metadata +96 -35
- data/README +0 -12
- data/lib/banco/get_file.rb +0 -43
- data/lib/banco/reader.rb +0 -64
- data/lib/banco/reporter.rb +0 -74
- data/lib/banco/viewable.rb +0 -181
- data/spec/banco/reader_spec.rb +0 -16
- data/spec/banco/reporter_spec.rb +0 -55
- data/spec/banco/transaction_spec.rb +0 -49
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'csv'
|
|
4
|
+
require_relative 'base'
|
|
5
|
+
|
|
6
|
+
module Banco
|
|
7
|
+
module Formatter
|
|
8
|
+
class Text < Base
|
|
9
|
+
def self.format_name = 'text'
|
|
10
|
+
|
|
11
|
+
def call = bottom_line
|
|
12
|
+
|
|
13
|
+
def menu
|
|
14
|
+
output = +''
|
|
15
|
+
output << "Enter :\n\n"
|
|
16
|
+
output << "'a' to view all transactions\n"
|
|
17
|
+
output << "'o' to view all outgoing transactions\n"
|
|
18
|
+
output << "'i' to view all incoming transactions\n"
|
|
19
|
+
output << "'m' for money out summary\n"
|
|
20
|
+
output << "'n' for money in summary\n"
|
|
21
|
+
output << "'b' for the bottom line\n"
|
|
22
|
+
output << "'s' to save summary as csv\n"
|
|
23
|
+
output << "'t' to save transactions as csv\n"
|
|
24
|
+
output << "\n'l' to load a new file\n"
|
|
25
|
+
output << "'+' to merge another file into the current set\n"
|
|
26
|
+
output << "\nor 'q' to quit\n\n\n"
|
|
27
|
+
output
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def transactions_all
|
|
31
|
+
output = +''
|
|
32
|
+
output << dashes << "\n"
|
|
33
|
+
output << "All transactions:\n"
|
|
34
|
+
output << "#{facts(@report.all_transactions)}\n\n"
|
|
35
|
+
@report.all_transactions.each do |trans|
|
|
36
|
+
output << if trans.debit_pence.zero?
|
|
37
|
+
"#{trans} + #{format_pence(trans.credit_pence)}\n"
|
|
38
|
+
else
|
|
39
|
+
"#{trans} - #{format_pence(trans.debit_pence)}\n"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
output << dashes << "\n\n"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def transactions_out
|
|
46
|
+
output = +''
|
|
47
|
+
output << dashes << "\n"
|
|
48
|
+
output << "Outgoing Transactions:\n"
|
|
49
|
+
output << "#{facts(@report.outgoing_trans)}\n\n"
|
|
50
|
+
@report.outgoing_trans.each { |t| output << "#{t} - #{format_pence(t.debit_pence)}\n" }
|
|
51
|
+
output << dashes << "\n\n"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def transactions_in
|
|
55
|
+
output = +''
|
|
56
|
+
output << dashes << "\n"
|
|
57
|
+
output << "Incoming Transactions :\n"
|
|
58
|
+
output << "#{facts(@report.incoming_trans)}\n\n"
|
|
59
|
+
@report.incoming_trans.each { |t| output << "#{t} + #{format_pence(t.credit_pence)}\n" }
|
|
60
|
+
output << dashes << "\n\n"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def money_out_summary
|
|
64
|
+
print_summary('Outgoings', @report.outgoings, @report.outgoing_total)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def money_in_summary
|
|
68
|
+
print_summary('Incomings', @report.incomings, @report.incoming_total)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def bottom_line
|
|
72
|
+
output = +''
|
|
73
|
+
output << dashes << "\n"
|
|
74
|
+
output << facts(@report.all_transactions).to_s.rjust(54) << "\n\n"
|
|
75
|
+
output << "Money In : #{format_pence(@report.incoming_total)}".rjust(54) << "\n"
|
|
76
|
+
output << "Money Out : #{format_pence(@report.outgoing_total)}".rjust(54) << "\n\n"
|
|
77
|
+
diff = @report.incoming_total - @report.outgoing_total
|
|
78
|
+
output << if @report.outgoing_total > @report.incoming_total
|
|
79
|
+
"Outgoings exceed Incomings, DEFICIT of #{format_pence(diff.abs)}".rjust(54)
|
|
80
|
+
else
|
|
81
|
+
"Incomings exceed Outgoings, SURPLUS of #{format_pence(diff)}".rjust(54)
|
|
82
|
+
end
|
|
83
|
+
output << "\n" << dashes << "\n\n"
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def save_summary_to_file(path)
|
|
87
|
+
CSV.open(path, 'w') do |csv|
|
|
88
|
+
csv << %w[Direction Category Total]
|
|
89
|
+
@report.outgoings.sort_by { |_, v| -v }.each do |k, v|
|
|
90
|
+
csv << ['Outgoing', k.strip, format('%.2f', v / 100.0)]
|
|
91
|
+
end
|
|
92
|
+
@report.incomings.sort_by { |_, v| -v }.each do |k, v|
|
|
93
|
+
csv << ['Incoming', k.strip, format('%.2f', v / 100.0)]
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def save_transactions_to_file(path)
|
|
99
|
+
CSV.open(path, 'w') do |csv|
|
|
100
|
+
csv << %w[Date Description Amount]
|
|
101
|
+
@report.all_transactions.each do |t|
|
|
102
|
+
amount = t.credit_pence.positive? ? t.credit_pence / 100.0 : -(t.debit_pence / 100.0)
|
|
103
|
+
csv << [t.date, t.description.strip, format('%.2f', amount)]
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def dashes
|
|
109
|
+
'---'.center(55, '-')
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def date_range
|
|
113
|
+
first = @report.all_transactions.first
|
|
114
|
+
last_t = @report.all_transactions.last
|
|
115
|
+
days = (first.parsed_date - last_t.parsed_date).to_i.abs + 1 if first&.parsed_date && last_t&.parsed_date
|
|
116
|
+
day_label = days == 1 ? 'day' : 'days'
|
|
117
|
+
day_str = days ? " — #{days} #{day_label}" : ''
|
|
118
|
+
"(#{last_t&.date} - #{first&.date})#{day_str}"
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def facts(transactions)
|
|
122
|
+
"#{transactions.size} transactions for period #{date_range}"
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
private
|
|
126
|
+
|
|
127
|
+
def format_pence(pence)
|
|
128
|
+
"£#{format('%10.2f', pence / 100.0)}"
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def print_summary(kind, hash, total)
|
|
132
|
+
output = +''
|
|
133
|
+
output << dashes << "\n"
|
|
134
|
+
output << "#{kind} Summary, totals from #{hash.size} different sources :\n"
|
|
135
|
+
output << "#{date_range}\n"
|
|
136
|
+
hash.sort_by { |_k, v| v }.reverse_each { |k, v| output << "#{k} #{format_pence(v)}\n".rjust(54) }
|
|
137
|
+
output << "\n"
|
|
138
|
+
output << "Total #{kind}: #{format_pence(total)}\n".rjust(54)
|
|
139
|
+
output << dashes << "\n\n"
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'banco/report'
|
|
4
|
+
|
|
5
|
+
module Banco
|
|
6
|
+
class Grouper
|
|
7
|
+
DEFAULT_PREFIX_LENGTH = 9
|
|
8
|
+
|
|
9
|
+
def initialize(transactions, prefix_length: DEFAULT_PREFIX_LENGTH, from: nil, to: nil)
|
|
10
|
+
@transactions = transactions
|
|
11
|
+
@prefix_length = prefix_length
|
|
12
|
+
@from = from
|
|
13
|
+
@to = to
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def call
|
|
17
|
+
clean = @transactions.reject { |t| t.credit_pence.zero? && t.debit_pence.zero? }
|
|
18
|
+
clean = filter_by_date(clean)
|
|
19
|
+
out, inc = clean.partition { |t| t.credit_pence.zero? && t.debit_pence.positive? }
|
|
20
|
+
Report.new(
|
|
21
|
+
all_transactions: clean,
|
|
22
|
+
outgoing_trans: out,
|
|
23
|
+
incoming_trans: inc,
|
|
24
|
+
outgoings: group(out, :debit_pence),
|
|
25
|
+
incomings: group(inc, :credit_pence)
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def filter_by_date(transactions)
|
|
32
|
+
return transactions if @from.nil? && @to.nil?
|
|
33
|
+
|
|
34
|
+
transactions.select { |t| in_range?(t) }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def in_range?(transaction)
|
|
38
|
+
return false if transaction.parsed_date.nil?
|
|
39
|
+
|
|
40
|
+
(@from.nil? || transaction.parsed_date >= @from) &&
|
|
41
|
+
(@to.nil? || transaction.parsed_date <= @to)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def group(transactions, attr)
|
|
45
|
+
transactions.each_with_object(Hash.new(0)) do |t, h|
|
|
46
|
+
h[t.description[0, @prefix_length]] += t.public_send(attr)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
data/lib/banco/parser.rb
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'csv'
|
|
4
|
+
require 'banco/transaction'
|
|
5
|
+
|
|
6
|
+
module Banco
|
|
7
|
+
class Parser
|
|
8
|
+
def initialize(file_path, skip_header: false, bank_format: BankFormat[:legacy])
|
|
9
|
+
@file_path = file_path
|
|
10
|
+
@skip_header = skip_header
|
|
11
|
+
@bank_format = bank_format
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def parse
|
|
15
|
+
rows = []
|
|
16
|
+
CSV.foreach(@file_path).with_index do |row, i|
|
|
17
|
+
next if @skip_header && i.zero?
|
|
18
|
+
|
|
19
|
+
parsed = parse_row(row, i)
|
|
20
|
+
rows << parsed if parsed
|
|
21
|
+
end
|
|
22
|
+
rows
|
|
23
|
+
rescue Errno::ENOENT
|
|
24
|
+
raise ArgumentError, "File not found: #{@file_path}"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def parse_row(row, index)
|
|
30
|
+
Transaction.from_row(row, @bank_format)
|
|
31
|
+
rescue ArgumentError => e
|
|
32
|
+
if index.zero? && e.message.include?('Non-numeric')
|
|
33
|
+
warn 'Skipping header row (use --header to suppress this warning)'
|
|
34
|
+
return nil
|
|
35
|
+
end
|
|
36
|
+
raise ArgumentError, "Row #{index + 1}: #{e.message}"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
data/lib/banco/report.rb
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Banco
|
|
4
|
+
Report = Data.define(:all_transactions, :outgoing_trans, :incoming_trans, :outgoings, :incomings) do
|
|
5
|
+
def outgoing_total = outgoings.values.sum
|
|
6
|
+
def incoming_total = incomings.values.sum
|
|
7
|
+
def surplus_pence = incoming_total - outgoing_total
|
|
8
|
+
def date_range = [all_transactions.first&.date, all_transactions.last&.date]
|
|
9
|
+
end
|
|
10
|
+
end
|
data/lib/banco/transaction.rb
CHANGED
|
@@ -1,32 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'date'
|
|
4
|
+
require 'banco/bank_format'
|
|
1
5
|
|
|
2
6
|
module Banco
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
Transaction = Data.define(:date, :description, :type, :credit_pence, :debit_pence, :parsed_date) do
|
|
8
|
+
class << self
|
|
9
|
+
def from_row(row, fmt = BankFormat[:legacy])
|
|
10
|
+
date_str = row[fmt.date_col]
|
|
11
|
+
credit, debit = money_columns(row, fmt)
|
|
12
|
+
new(
|
|
13
|
+
date: date_str,
|
|
14
|
+
description: row[fmt.description_col].to_s.upcase.ljust(22)[0, 22],
|
|
15
|
+
type: (fmt.type_col && row[fmt.type_col]).to_s.upcase.ljust(8)[0, 8],
|
|
16
|
+
credit_pence: credit,
|
|
17
|
+
debit_pence: debit,
|
|
18
|
+
parsed_date: parse_date(date_str, fmt.date_fmt)
|
|
19
|
+
)
|
|
20
|
+
end
|
|
15
21
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
# When credit and debit share a column the value is a signed amount:
|
|
25
|
+
# positive is incoming (credit), negative is outgoing (debit).
|
|
26
|
+
def money_columns(row, fmt)
|
|
27
|
+
return [parse_pence(row[fmt.credit_col]), parse_pence(row[fmt.debit_col])] if fmt.credit_col != fmt.debit_col
|
|
28
|
+
|
|
29
|
+
amount = parse_pence(row[fmt.credit_col])
|
|
30
|
+
amount.negative? ? [0, amount.abs] : [amount, 0]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def parse_pence(str)
|
|
34
|
+
return 0 if str.nil? || str.strip.empty?
|
|
19
35
|
|
|
20
|
-
|
|
21
|
-
|
|
36
|
+
Float(str) # validates; exact conversion uses Rational below
|
|
37
|
+
(str.to_r * 100).to_i
|
|
38
|
+
rescue ArgumentError
|
|
39
|
+
raise ArgumentError, "Non-numeric money value: #{str.inspect}"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def parse_date(str, fmt_str)
|
|
43
|
+
return nil if str.nil? || str.strip.empty? || fmt_str.nil?
|
|
44
|
+
|
|
45
|
+
Date.strptime(str, fmt_str)
|
|
46
|
+
rescue Date::Error
|
|
47
|
+
nil
|
|
48
|
+
end
|
|
22
49
|
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
50
|
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
51
|
+
def to_s = "#{date} #{type} #{description}"
|
|
52
|
+
end
|
|
32
53
|
end
|
data/lib/banco.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'banco/version'
|
|
4
|
+
require 'banco/bank_format'
|
|
5
|
+
require 'banco/transaction'
|
|
6
|
+
require 'banco/report'
|
|
7
|
+
require 'banco/grouper'
|
|
8
|
+
require 'banco/parser'
|
|
9
|
+
require 'banco/formatter/base'
|
|
10
|
+
require 'banco/formatter/text'
|
|
11
|
+
require 'banco/formatter/json_formatter'
|
|
12
|
+
require 'banco/formatter/csv_formatter'
|
|
13
|
+
require 'banco/cli'
|
|
14
|
+
require 'banco/file_picker'
|
|
15
|
+
|
|
16
|
+
user_formats = File.expand_path('~/.banco/formats.rb')
|
|
17
|
+
load user_formats if File.exist?(user_formats)
|
metadata
CHANGED
|
@@ -1,63 +1,128 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: banco
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- s33d
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: csv
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: rake
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
13
40
|
- !ruby/object:Gem::Dependency
|
|
14
41
|
name: rspec
|
|
15
42
|
requirement: !ruby/object:Gem::Requirement
|
|
16
43
|
requirements:
|
|
17
44
|
- - "~>"
|
|
18
45
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
46
|
+
version: '3.13'
|
|
20
47
|
type: :development
|
|
21
48
|
prerelease: false
|
|
22
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
50
|
requirements:
|
|
24
51
|
- - "~>"
|
|
25
52
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
53
|
+
version: '3.13'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: rubocop
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
type: :development
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: rubocop-performance
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '0'
|
|
75
|
+
type: :development
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '0'
|
|
82
|
+
- !ruby/object:Gem::Dependency
|
|
83
|
+
name: rubocop-rspec
|
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
89
|
+
type: :development
|
|
90
|
+
prerelease: false
|
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0'
|
|
96
|
+
description: Summarise bank statement CSV files from the command line. Supports multiple
|
|
97
|
+
bank CSV formats, date filtering, and text/JSON/CSV output.
|
|
40
98
|
email: code@s33d.co
|
|
41
99
|
executables:
|
|
42
100
|
- banco
|
|
43
101
|
extensions: []
|
|
44
102
|
extra_rdoc_files: []
|
|
45
103
|
files:
|
|
104
|
+
- CHANGELOG.md
|
|
46
105
|
- LICENSE
|
|
47
|
-
- README
|
|
106
|
+
- README.md
|
|
48
107
|
- bin/banco
|
|
49
|
-
- lib/banco
|
|
50
|
-
- lib/banco/
|
|
51
|
-
- lib/banco/
|
|
108
|
+
- lib/banco.rb
|
|
109
|
+
- lib/banco/bank_format.rb
|
|
110
|
+
- lib/banco/cli.rb
|
|
111
|
+
- lib/banco/file_picker.rb
|
|
112
|
+
- lib/banco/formatter/base.rb
|
|
113
|
+
- lib/banco/formatter/csv_formatter.rb
|
|
114
|
+
- lib/banco/formatter/json_formatter.rb
|
|
115
|
+
- lib/banco/formatter/text.rb
|
|
116
|
+
- lib/banco/grouper.rb
|
|
117
|
+
- lib/banco/parser.rb
|
|
118
|
+
- lib/banco/report.rb
|
|
52
119
|
- lib/banco/transaction.rb
|
|
53
|
-
- lib/banco/
|
|
54
|
-
- spec/banco/reader_spec.rb
|
|
55
|
-
- spec/banco/reporter_spec.rb
|
|
56
|
-
- spec/banco/transaction_spec.rb
|
|
120
|
+
- lib/banco/version.rb
|
|
57
121
|
homepage: https://github.com/s33dco/banco
|
|
58
122
|
licenses:
|
|
59
123
|
- MIT
|
|
60
|
-
metadata:
|
|
124
|
+
metadata:
|
|
125
|
+
rubygems_mfa_required: 'true'
|
|
61
126
|
post_install_message: Thanks for installing, hope your numbers are positive!
|
|
62
127
|
rdoc_options: []
|
|
63
128
|
require_paths:
|
|
@@ -66,18 +131,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
66
131
|
requirements:
|
|
67
132
|
- - ">="
|
|
68
133
|
- !ruby/object:Gem::Version
|
|
69
|
-
version: '
|
|
134
|
+
version: '3.3'
|
|
70
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
136
|
requirements:
|
|
72
137
|
- - ">="
|
|
73
138
|
- !ruby/object:Gem::Version
|
|
74
139
|
version: '0'
|
|
75
140
|
requirements: []
|
|
76
|
-
rubygems_version:
|
|
77
|
-
signing_key:
|
|
141
|
+
rubygems_version: 4.0.18
|
|
78
142
|
specification_version: 4
|
|
79
|
-
summary:
|
|
80
|
-
test_files:
|
|
81
|
-
- spec/banco/reader_spec.rb
|
|
82
|
-
- spec/banco/transaction_spec.rb
|
|
83
|
-
- spec/banco/reporter_spec.rb
|
|
143
|
+
summary: Summarise bank statement CSV files from the command line
|
|
144
|
+
test_files: []
|
data/README
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
Welcome to Banco !
|
|
2
|
-
|
|
3
|
-
Banco has been developed to summarize statements downloaded from your bank.
|
|
4
|
-
Install as a Rubygem, navigate to the directory your .csv files are in and execute from the command line with 'banco'.
|
|
5
|
-
|
|
6
|
-
Banco will only accept comma seperated value files (.csv) and will produce a summary for the period uploaded from the file.
|
|
7
|
-
|
|
8
|
-
Remove the header line from your downloaded bank statement, ensure the columns are ordered date, description, type of charge, money in an money out from left to right, any columns right of the fifth will be ignored. Banco will total the incoming & outgoing transactions for the period. Reporting the bottom line aswell as summing up the values for similar transactions. This is achieved by matching the description name, currently set at the first 9 characters of the string, (:total_outgoing :total_incoming - class Reporter), you can change this to be more or less exact.
|
|
9
|
-
|
|
10
|
-
Hope your numbers are positive !
|
|
11
|
-
https://github.com/s33dco/banco
|
|
12
|
-
https://rubygems.org/gems/banco
|
data/lib/banco/get_file.rb
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
module Banco
|
|
3
|
-
class GetFile
|
|
4
|
-
attr_reader :name, :csv_file_name, :summary_name
|
|
5
|
-
|
|
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
|
|
17
|
-
|
|
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
|
|
24
|
-
|
|
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
|
|
34
|
-
end
|
|
35
|
-
|
|
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
|
|
43
|
-
end
|
data/lib/banco/reader.rb
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
require_relative 'transaction'
|
|
3
|
-
require_relative 'viewable'
|
|
4
|
-
require 'csv'
|
|
5
|
-
|
|
6
|
-
module Banco
|
|
7
|
-
class Reader
|
|
8
|
-
include Viewable
|
|
9
|
-
|
|
10
|
-
attr_reader :all_from_csv, :report_name, :csv_file_name
|
|
11
|
-
|
|
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
|
|
17
|
-
|
|
18
|
-
def read_in_csv_data
|
|
19
|
-
@csv_row_count = 1
|
|
20
|
-
|
|
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
|
|
45
|
-
end
|
|
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
|
|
55
|
-
end
|
|
56
|
-
|
|
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
|
|
64
|
-
end
|