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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c230ed99ba0f6d76fa738cc6ff8a3ea55173c6051765bff9971591b669df8fc
4
- data.tar.gz: 12a1a50bd2fed725e4b339b212e2ba71342a240ef4a98639faa69894e60fa1c1
3
+ metadata.gz: ce7ba84a2102c4036382a535b0da7a40ea8d0e5230ecb5bed701f63ae823febd
4
+ data.tar.gz: 03fd4cd2808134359200dd681f9b1c6905f0aa86c9c0c3e96a5407ab7aaa8839
5
5
  SHA512:
6
- metadata.gz: ee6561fc735f9ecbda6673c264c48d9ef71bfb8a1f2483e6a9feee865469c0a7f2d36c1d239e9220ff1ab71350575b2af5b000447035e20ce95ec0f47eba8be0
7
- data.tar.gz: ef5106aad369fd69f76c0425127db3fb0287281914075417a863ce501f902baa5d81d6b2ee365edda16e3b34f66dfa06bad7c8ee1e10317dac1ceec3a44ebacd
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
- def self.starter
11
- Viewable::prompt
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
- end
17
-
18
- Viewable::hello
19
- report = starter
20
- loop do
21
- report.menu
22
- answer = gets.chomp.downcase
23
- case answer
24
- when 'a'
25
- print report.transactions_all
26
- when 'o'
27
- print report.transactions_out
28
- when "i"
29
- print report.transactions_in
30
- when "m"
31
- print report.money_out_summary
32
- when "n"
33
- print report.money_in_summary
34
- when "b"
35
- print report.bottom_line
36
- when "l"
37
- report = starter
38
- when "s"
39
- report.save_summary_to_file
40
- when "t"
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
-
@@ -1,41 +1,43 @@
1
+
1
2
  module Banco
2
- class GetFile
3
- attr_reader :name, :csv_file_name, :summary_name
3
+ class GetFile
4
+ attr_reader :name, :csv_file_name, :summary_name
4
5
 
5
- def initialize
6
- @csv_file_name = gets.chomp.downcase
7
- if @csv_file_name == 'q'
8
- Viewable::farewell
9
- exit
10
- else
11
- file_checker_cleaner(@csv_file_name)
12
- @name = @csv_file_name.split('.').first
13
- @doctype = @csv_file_name.split('.').last
14
- @summary_name = @name
15
- @csv_file_name
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
- def file_checker_cleaner(filename)
20
- if filename =~/([^\s]+(\.csv)$)/
21
- puts "\nloading #{filename}..."
22
- else
23
- puts "#{filename} won't work !".center(54)
24
- puts "try again or 'q' to exit".center(54)
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
- end
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 __FILE__ == $0
33
- file = Banco::GetFile.new()
34
- file.make_name
35
- puts "\n\n\n"
36
- p file.valid_file
37
- p file.name
38
- p file.summary_name
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
-
@@ -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
- class Reader
7
- include Viewable
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
- def read_in_csv_data
18
- begin
19
- @csv_row_count = 1
10
+ attr_reader :all_from_csv, :report_name, :csv_file_name
20
11
 
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
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
- rescue ArgumentError => e
27
- non_numeric_in_csv(e, @csv_row_count)
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
- rescue Errno::ENOENT => e
34
- puts "Can't find file #{@csv_file_name} - have another go or (q) quit\n\n"
35
- loop do
36
- input = gets.chomp.downcase
37
- case input
38
- when 'q'
39
- Viewable::farewell
40
- exit
41
- when /([^\s]+(\.csv)$)/
42
- @csv_file_name = input
43
- break
44
- else
45
- puts "\ninvalid file - try again or 'q' to quit\n\n"
46
- end
47
- end
48
- retry
49
- end
50
- end
51
-
52
- def non_numeric_in_csv(exception, row_number)
53
- reason = exception.message.split(':')
54
- puts "Please check row #{row_number} of #{@csv_file_name},"
55
- puts "#{reason.last} should be a numeric value".rjust(54)
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
- 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
58
55
  end
59
56
 
60
- if __FILE__ == $0
61
- reader = Banco::Reader.new("test.csv", "test")
62
- reader.read_in_csv_data
63
- puts reader.report_name
64
- puts reader.csv_file_name
65
- puts reader.all_from_csv
66
- p reader
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
@@ -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
- 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
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
- 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
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
- def remove_blank_lines
39
- @all_transactions.delete_if{|trans| trans.moneyin == 0 && trans.moneyout == 0}
40
- end
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
- def split_in_out
43
- @outgoing_trans, @incoming_trans = @all_transactions.partition{|trans| trans.moneyin == 0 && trans.moneyout > 0}
44
- end
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
- def total_outgoing
47
- @outgoing_trans.each{|trans| @outgoings[trans.description[0..8]] += trans.moneyout}
48
- @outgoing_total = @outgoings.values.map.reduce(:+)
49
- end
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
- if __FILE__ == $0
60
- reader = Banco::Reader.new("test.csv", "test")
61
- reader.read_in_csv_data
62
- puts "\n\n\n#all csv data from reader object\n\n"
63
- puts "#{reader.all_from_csv}\n\n"
64
- report = Banco::Reporter.new(reader.csv_file_name, reader.report_name, reader.all_from_csv)
65
- puts "#{report.name} is the Reporter object's name\nReporter object contents below, (3 arrays, 2 hashes):\n\n"
66
- puts "\n\nall transactions array\n"
67
- p report.all_transactions
68
- puts "\n\noutgoings array\n"
69
- p report.outgoing_trans
70
- puts "\n\nincomings array\n"
71
- p report.incoming_trans
72
- puts "\n\nOutgoings hash\n"
73
- p report.outgoings
74
- puts "\n\nIncomings hash\n"
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
@@ -1,31 +1,32 @@
1
+
1
2
  module Banco
2
- class Transaction
3
- require 'bigdecimal'
4
- attr_reader :date, :description, :type, :moneyin, :moneyout, :csv_row_count
3
+ class Transaction
4
+ require 'bigdecimal'
5
+ attr_reader :date, :description, :type, :moneyin, :moneyout, :csv_row_count
5
6
 
6
- def initialize(date_string, description, type, moneyin, moneyout, csv_row_count)
7
- @csv_row_count = csv_row_count
8
- @moneyin = convert(moneyin)
9
- @moneyout = convert(moneyout)
10
- @date = date_string
11
- @description = '%-22.22s' % "#{description.upcase}"
12
- @type = '%-8.8s' % "#{type.upcase}"
13
- end
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
- def convert(money)
16
- money.nil? ? BigDecimal('0') : BigDecimal(money)
17
- end
16
+ def convert(money)
17
+ money.nil? ? BigDecimal('0') : BigDecimal(money)
18
+ end
18
19
 
19
- def to_s
20
- "#{date} #{type} #{description}"
21
- end
22
- end
20
+ def to_s
21
+ "#{date} #{type} #{description}"
22
+ end
23
+ end
23
24
  end
24
25
 
25
- if __FILE__ == $0
26
- trans = Banco::Transaction.new("01/01/17", "Supermarket","Purchase", "72.90", "0","1")
27
- p trans
28
- t = Banco::Transaction.new
29
- t.send(:initialize, "02/02/18", "new way", "credit", "0", '111.11','2')
30
- p t
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
@@ -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 = sprintf("%10.2f", money.truncate(2))
19
+ format = format('%10.2f', money.truncate(2))
19
20
  "£#{format}"
20
21
  end
21
22
 
22
23
  def dashes
23
- "---".center(55,"-")
24
+ '---'.center(55, '-')
24
25
  end
25
26
 
26
27
  def date_range
27
- "(#{self.all_transactions.last.date} - #{self.all_transactions.first.date})"
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("Outgoings", self.outgoings, self.outgoing_total)
36
+ print_summary('Outgoings', outgoings, outgoing_total)
36
37
  end
37
38
 
38
39
  def money_in_summary
39
- print_summary("Incomings", self.incomings, self.incoming_total)
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(self.all_transactions)}\n\n"
48
- self.all_transactions.each do |trans|
49
- if trans.moneyout == 0
50
- output << "#{trans} + #{to_pounds(trans.moneyin)}\n"
51
- else
52
- output << "#{trans} - #{to_pounds(trans.moneyout)}\n"
53
- end
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(self.outgoing_trans)}\n\n"
65
- self.outgoing_trans.each{|trans| output << "#{trans} - #{to_pounds(trans.moneyout)}\n"}
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(self.incoming_trans)}\n\n"
76
- self.incoming_trans.each{|trans| output << "#{trans} + #{to_pounds(trans.moneyin)}\n"}
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 << "#{facts(self.all_transactions)}".rjust(54)
99
+ output << facts(all_transactions).to_s.rjust(54)
99
100
  output << "\n\n"
100
- output << "Money In : #{to_pounds(self.incoming_total)}".rjust(54)
101
+ output << "Money In : #{to_pounds(incoming_total)}".rjust(54)
101
102
  output << "\n"
102
- output << "Money Out : #{to_pounds(self.outgoing_total)}".rjust(54)
103
+ output << "Money Out : #{to_pounds(outgoing_total)}".rjust(54)
103
104
  output << "\n\n"
104
- diff = self.incoming_total - self.outgoing_total
105
- if self.outgoing_total > self.incoming_total
106
- output << "Outgoings exceed Incomings, DEFICIT of #{to_pounds(diff)}".rjust(54)
107
- else
108
- output << "Incomings exceed Outgoings, SURPLUS of #{to_pounds(diff)}".rjust(54)
109
- end
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 "*".center(55,'*')
118
- puts " Banco ".center(55,'*')
119
- puts " hope your numbers were positive ".center(55,'*')
120
- puts " code@s33d.co ".center(55,'*')
121
- puts "*".center(55,'*')
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 "Banco will summarize your bank statements.".center(55)
129
- puts "import a .csv file for review".center(55)
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 "the .csv file should have :".center(55)
132
- puts "NO headers".center(55)
133
- puts "with columns ordered (left to right)".center(55)
134
- puts "date - description - type - money in - money out".center(55)
135
- puts "all additional columns will be ignored".center(55)
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 "Enter the name of you .csv file to review".center(54)
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="#{self.name}_summary.txt")
147
- File.open(to_file, "w") do |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 #{self.csv_file_name}"
168
+ file.puts "summarized by Banco from #{csv_file_name}"
151
169
  file.puts "\n"
152
- file.puts self.money_out_summary
170
+ file.puts transactions_out
153
171
  file.puts "\n"
154
- file.puts self.money_in_summary
172
+ file.puts transactions_in
155
173
  file.puts "\n"
156
- file.puts self.bottom_line
174
+ file.puts bottom_line
157
175
  file.puts "\n"
158
- file.puts "code@s33d.co".rjust(54)
176
+ file.puts '♥️ code@s33d.co'.rjust(54)
159
177
  end
160
- puts "\n\nfile saved as #{self.name}_summary.txt\n\n"
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
@@ -1,14 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'banco/reader'
2
4
  module Banco
3
- describe Reader do
4
- before do
5
- csv_file_name = "test.csv"
6
- report_name = "test"
7
- @testreader = Banco::Reader.new(csv_file_name, report_name)
8
- @testreader.read_in_csv_data
9
- end
10
- it "should produce an array for all rows on csv file" do
11
- expect(@testreader.all_from_csv.length).to eq(10)
12
- end
13
- end
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
@@ -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
- describe Reporter do
5
- before do
6
- csv_file_name = "test.csv"
7
- report_name = "test"
8
- @testreader = Banco::Reader.new(csv_file_name, report_name)
9
- @testreader.read_in_csv_data
10
- @tester = Banco::Reporter.new('test.csv', 'test', @testreader.all_from_csv)
11
- @tester.remove_blank_lines
12
- @tester.split_in_out
13
- @tester.total_outgoing
14
- @tester.total_incoming
15
- end
16
-
17
- it "should remove transactions with zero values (moneyin / moneyout)" do
18
- expect(@tester.all_transactions.size).to eq(8)
19
- end
20
-
21
-
22
- it "should produce an array of incoming transactions" do
23
- expect(@tester.incoming_trans.size).to eq(4)
24
- end
25
-
26
- it "should produce an array of outgoing transactions" do
27
- expect(@tester.outgoing_trans.size).to eq(4)
28
- end
29
-
30
- it "should produce a hash of outgoing transactions" do
31
- expect(@tester.outgoings.size).to eq(2)
32
- end
33
-
34
- it "should produce a hash of incoming transactions" do
35
- expect(@tester.incomings.size).to eq(2)
36
- end
37
-
38
- it "should sum incoming transactions by matching description string" do
39
- expect(@tester.incomings['INCOMING2']).to eq(183.34)
40
- end
41
-
42
- it "should sum outgoing transactions by matching description string" do
43
- expect(@tester.outgoings['OUTGOING2']).to eq(182.68)
44
- end
45
-
46
- it "should sum total incoming transactions" do
47
- expect(@tester.incoming_total).to eq(321.58)
48
- end
49
-
50
- it "should sum total outgoing transactions" do
51
- expect(@tester.outgoing_total).to eq(320.92)
52
- end
53
- end
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
- describe Transaction do
5
- before do
6
- @trans1 = Transaction.new("12/01/17","some transaction", "credit", "57.91", "0.00", "1")
7
- @trans2 = Transaction.new("13/01/17","some other transaction", "debit", "0.00", "57.91",'2')
8
- end
9
-
10
- # it "Should convert money in values to pence" do
11
- # expect(@trans1.moneyin).to eq(5791)
12
- # end
13
-
14
- # it "Should convert money out values to pence" do
15
- # expect(@trans2.moneyout).to eq(5791)
16
- # end
17
-
18
- it "Should have a description string of 22 characters (upcase)" do
19
- expect(@trans2.description).to eq("SOME OTHER TRANSACTION")
20
- expect(@trans1.description).to eq("SOME TRANSACTION ")
21
- end
22
-
23
- it "Should have a type string upcased and 8 characters long" do
24
- expect(@trans2.type).to eq("DEBIT ")
25
- end
26
-
27
- it "Should have a date string" do
28
- expect(@trans1.date).to eq("12/01/17")
29
- end
30
-
31
- it "Should have a row number" do
32
- expect(@trans2.csv_row_count).to eq("2")
33
- end
34
-
35
- it "should have a to_s of all date description type" do
36
- expect(@trans1.to_s).to eq("12/01/17 CREDIT SOME TRANSACTION ")
37
- end
38
-
39
- it "convert empty strings in money columns to integers" do
40
- expect(@trans1.moneyout).to eq(0)
41
- end
42
-
43
- it "convert empty strings in money columns to integers" do
44
- expect(@trans2.moneyin).to eq(0)
45
- end
46
- end
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.2
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-06-14 00:00:00.000000000 Z
11
+ date: 2019-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec