Module: Banco::Viewable
Class Method Summary collapse
Instance Method Summary collapse
- #bottom_line ⇒ Object
- #dashes ⇒ Object
- #date_range ⇒ Object
- #facts(transactions) ⇒ Object
- #menu ⇒ Object
- #money_in_summary ⇒ Object
- #money_out_summary ⇒ Object
- #print_summary(kind, hash, total) ⇒ Object
- #save_summary_to_file(to_file = "#{name}_summary.txt") ⇒ Object
- #save_transactions_to_file(to_file = "#{name}_transactions.txt") ⇒ Object
- #to_pounds(money) ⇒ Object
- #transactions_all ⇒ Object
- #transactions_in ⇒ Object
- #transactions_out ⇒ Object
Class Method Details
.farewell ⇒ Object
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/banco/viewable.rb', line 116 def self.farewell puts "\n\n" puts '*'.center(55, '*') puts ' Banco '.center(55, '*') puts ' hope your numbers were positive '.center(55, '*') puts ' ♥️ [email protected] '.center(56, '*') puts '*'.center(55, '*') puts "\n\n\n" exit end |
.hello ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/banco/viewable.rb', line 127 def self.hello puts "\n\n" puts 'Banco will summarize your bank statements.'.center(55) puts 'import a .csv file for review'.center(55) puts "\n\n" puts 'the .csv file should have :'.center(55) puts 'NO headers'.center(55) puts 'with columns ordered (left to right)'.center(55) puts 'date - description - type - money in - money out'.center(55) puts 'all additional columns will be ignored'.center(55) end |
.prompt ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/banco/viewable.rb', line 139 def self.prompt puts "\n\n" puts 'Enter the name of you .csv file to review'.center(54) puts "(use 'test.csv' for the test file)".center(54) puts "or 'q' to quit...".center(55) puts "\n\n" end |
Instance Method Details
#bottom_line ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/banco/viewable.rb', line 95 def bottom_line output = '' output << dashes output << "\n" output << facts(all_transactions).to_s.rjust(54) output << "\n\n" output << "Money In : #{to_pounds(incoming_total)}".rjust(54) output << "\n" output << "Money Out : #{to_pounds(outgoing_total)}".rjust(54) output << "\n\n" diff = incoming_total - outgoing_total output << if outgoing_total > incoming_total "Outgoings exceed Incomings, DEFICIT of #{to_pounds(diff)}".rjust(54) else "Incomings exceed Outgoings, SURPLUS of #{to_pounds(diff)}".rjust(54) end output << "\n" output << dashes output << "\n\n" end |
#dashes ⇒ Object
23 24 25 |
# File 'lib/banco/viewable.rb', line 23 def dashes '---'.center(55, '-') end |
#date_range ⇒ Object
27 28 29 |
# File 'lib/banco/viewable.rb', line 27 def date_range "(#{all_transactions.last.date} - #{all_transactions.first.date})" end |
#facts(transactions) ⇒ Object
31 32 33 |
# File 'lib/banco/viewable.rb', line 31 def facts(transactions) "#{transactions.size} transactions for period #{date_range}" end |
#menu ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/banco/viewable.rb', line 4 def puts "Enter :\n" puts "'a' to view all transactions" puts "'o' to view all outgoing transactions" puts "'i' to view all incoming transactions" puts "'m' for money out summary" puts "'n' for money in summary" puts "'b' for the bottom line" puts "'s' to save summaries to file" puts "'t' to save transactions to file" puts "\n'l' to load a new file\n" puts "\nor 'q' to quit\n\n\n" end |
#money_in_summary ⇒ Object
39 40 41 |
# File 'lib/banco/viewable.rb', line 39 def money_in_summary print_summary('Incomings', incomings, incoming_total) end |
#money_out_summary ⇒ Object
35 36 37 |
# File 'lib/banco/viewable.rb', line 35 def money_out_summary print_summary('Outgoings', outgoings, outgoing_total) end |
#print_summary(kind, hash, total) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/banco/viewable.rb', line 82 def print_summary(kind, hash, total) output = '' output << dashes output << "\n" output << "#{kind} Summary, totals from #{hash.size} different sources :\n" output << "#{date_range}\n" hash.sort_by { |_k, v| v }.reverse.each { |k, v| output << "#{k} #{to_pounds(v)}\n".rjust(54) } output << "\n" output << "Total #{kind}: #{to_pounds(total)}\n".rjust(54) output << dashes output << "\n\n" end |
#save_summary_to_file(to_file = "#{name}_summary.txt") ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/banco/viewable.rb', line 147 def save_summary_to_file(to_file = "#{name}_summary.txt") File.open(to_file, 'w') do |file| t = Time.now file.puts t.strftime("\n\nprinted : %d %b %y at %I:%M%P") file.puts "summarized by Banco from #{csv_file_name}" file.puts "\n" file.puts money_out_summary file.puts "\n" file.puts money_in_summary file.puts "\n" file.puts bottom_line file.puts "\n" file.puts '♥️ [email protected]'.rjust(54) end puts "\n\nfile saved as #{name}_summary.txt\n\n" end |
#save_transactions_to_file(to_file = "#{name}_transactions.txt") ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/banco/viewable.rb', line 164 def save_transactions_to_file(to_file = "#{name}_transactions.txt") File.open(to_file, 'w') do |file| t = Time.now file.puts t.strftime("\n\nprinted : %d %b %y at %I:%M%P") file.puts "summarized by Banco from #{csv_file_name}" file.puts "\n" file.puts transactions_out file.puts "\n" file.puts transactions_in file.puts "\n" file.puts bottom_line file.puts "\n" file.puts '♥️ [email protected]'.rjust(54) end puts "\n\nfile saved as #{name}_transactions.txt\n\n" end |
#to_pounds(money) ⇒ Object
18 19 20 21 |
# File 'lib/banco/viewable.rb', line 18 def to_pounds(money) format = format('%10.2f', money.truncate(2)) "£#{format}" end |
#transactions_all ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/banco/viewable.rb', line 43 def transactions_all output = '' output << dashes output << "\n" output << "All transactions:\n" output << "#{facts(all_transactions)}\n\n" all_transactions.each do |trans| output << if trans.moneyout == 0 "#{trans} + #{to_pounds(trans.)}\n" else "#{trans} - #{to_pounds(trans.moneyout)}\n" end end output << dashes output << "\n\n" end |
#transactions_in ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/banco/viewable.rb', line 71 def transactions_in output = '' output << dashes output << "\n" output << "Incoming Transactions :\n" output << "#{facts(incoming_trans)}\n\n" incoming_trans.each { |trans| output << "#{trans} + #{to_pounds(trans.)}\n" } output << dashes output << "\n\n" end |
#transactions_out ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/banco/viewable.rb', line 60 def transactions_out output = '' output << dashes output << "\n" output << "Outgoing Transactions:\n" output << "#{facts(outgoing_trans)}\n\n" outgoing_trans.each { |trans| output << "#{trans} - #{to_pounds(trans.moneyout)}\n" } output << dashes output << "\n\n" end |