module Banco::Viewable

Public Class Methods

farewell() click to toggle source
# 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 '  ♥️  code@s33d.co   '.center(56, '*')
  puts '*'.center(55, '*')
  puts "\n\n\n"
  exit
end
hello() click to toggle source
# 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() click to toggle source
# 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

Public Instance Methods

bottom_line() click to toggle source
# 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() click to toggle source
# File lib/banco/viewable.rb, line 23
def dashes
  '---'.center(55, '-')
end
date_range() click to toggle source
# File lib/banco/viewable.rb, line 27
def date_range
  "(#{all_transactions.last.date} - #{all_transactions.first.date})"
end
facts(transactions) click to toggle source
# File lib/banco/viewable.rb, line 31
def facts(transactions)
  "#{transactions.size} transactions for period #{date_range}"
end
menu() click to toggle source
money_in_summary() click to toggle source
# File lib/banco/viewable.rb, line 39
def money_in_summary
  print_summary('Incomings', incomings, incoming_total)
end
money_out_summary() click to toggle source
# File lib/banco/viewable.rb, line 35
def money_out_summary
  print_summary('Outgoings', outgoings, outgoing_total)
end
print_summary(kind, hash, total) click to toggle source
save_summary_to_file(to_file = " click to toggle source
# 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 '♥️ code@s33d.co'.rjust(54)
  end
  puts "\n\nfile saved as #{name}_summary.txt\n\n"
end
save_transactions_to_file(to_file = " click to toggle source
# 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 '♥️ code@s33d.co'.rjust(54)
  end
  puts "\n\nfile saved as #{name}_transactions.txt\n\n"
end
to_pounds(money) click to toggle source
# File lib/banco/viewable.rb, line 18
def to_pounds(money)
  format = format('%10.2f', money.truncate(2))
  "£#{format}"
end
transactions_all() click to toggle source
# 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.moneyin)}\n"
              else
                "#{trans} - #{to_pounds(trans.moneyout)}\n"
              end
  end
  output << dashes
  output << "\n\n"
end
transactions_in() click to toggle source
# 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.moneyin)}\n" }
  output << dashes
  output << "\n\n"
end
transactions_out() click to toggle source
# 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