class Layout
Public Class Methods
clear()
click to toggle source
# File lib/moneymanager/layout.rb, line 61 def self.clear print "\e[H\e[2J" end
formatted_amount(amount)
click to toggle source
# File lib/moneymanager/layout.rb, line 32 def self.formatted_amount(amount) s = format('%.2f €', amount) amount < 0 ? s.red : s.green end
print_generic_rows(rows)
click to toggle source
# File lib/moneymanager/layout.rb, line 45 def self.print_generic_rows(rows) return unless rows.count > 0 sum = rows.reduce(0) { |tot, row| tot + row.last } table = Terminal::Table.new rows.each do |row| table.add_row [ { value: row[0], alignment: :left }, { value: formatted_amount(row.last), alignment: :right } ] end table.add_separator table.add_row [{ value: formatted_amount(sum), colspan: 2, alignment: :right }] puts table end
print_multiple(entries)
click to toggle source
# File lib/moneymanager/layout.rb, line 2 def self.print_multiple(entries) if entries.count == 1 print_single(entries.first) else clear rows = entries.map { |entry| [entry.formatted_approved, entry.formatted_is_bank_tranfer, entry.date.strftime('%d/%m/%y'), entry.tag, entry.reason[0...50], entry.formatted_amount, entry.digest[0...6]] } table = Terminal::Table.new headings: ['✔/✖︎', '♻︎', 'Date', 'Tag', 'Reason', 'Amount', 'SHA1'], rows: rows table.align_column(5, :right) table.align_column(0, :center) puts table end end
print_single(entry)
click to toggle source
# File lib/moneymanager/layout.rb, line 17 def self.print_single(entry) clear hash = { date: entry.date, reason: entry.reason, amount: entry.formatted_amount, company: entry.company, approved: entry.formatted_approved, bank_transfer: entry.formatted_is_bank_tranfer, tag: entry.tag } rows = hash.map { |k, v| [k.to_s.capitalize, v] } puts Terminal::Table.new rows: rows end
print_single_value(total)
click to toggle source
# File lib/moneymanager/layout.rb, line 37 def self.print_single_value(total) table = Terminal::Table.new do |t| t << [formatted_amount(total)] end table.align_column(0, :right) puts table end