Class: Layout
- Inherits:
-
Object
- Object
- Layout
- Defined in:
- lib/moneymanager/layout.rb
Class Method Summary collapse
- .clear ⇒ Object
- .formatted_amount(amount) ⇒ Object
- .print_generic_rows(rows) ⇒ Object
- .print_multiple(entries) ⇒ Object
- .print_single(entry) ⇒ Object
- .print_single_value(total) ⇒ Object
Class Method Details
.clear ⇒ Object
54 55 56 |
# File 'lib/moneymanager/layout.rb', line 54 def self.clear print "\e[H\e[2J" end |
.formatted_amount(amount) ⇒ Object
26 27 28 29 |
# File 'lib/moneymanager/layout.rb', line 26 def self.formatted_amount(amount) s = amount.to_s + ' €' amount < 0 ? s.red : s.green end |
.print_generic_rows(rows) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/moneymanager/layout.rb', line 39 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 = rows.each { |row| table.add_row [ { :value => row[0], :alignment => :left}, { :value => formatted_amount(row.last), :alignment => :right }] } table.add_separator table.add_row [{ :value => formatted_amount(sum), :colspan => 2, :alignment => :right }] puts table end |
.print_multiple(entries) ⇒ Object
2 3 4 5 6 7 8 9 10 11 |
# File 'lib/moneymanager/layout.rb', line 2 def self.print_multiple(entries) clear rows = entries.map { |entry| [entry.formatted_approved, entry.date.strftime('%y/%m/%d'), entry.tag, entry.reason[0...50], entry.formatted_amount] } table = Terminal::Table.new headings: ['✔/✖︎', 'Date', 'Tag', 'Reason', 'Amount'], rows: rows table.align_column(4, :right) table.align_column(0, :center) puts table end |
.print_single(entry) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/moneymanager/layout.rb', line 13 def self.print_single(entry) hash = { date: entry.date, reason: entry.reason, amount: entry.formatted_amount, company: entry.company, approved: entry.formatted_approved, tag: entry.tag } rows = hash.map { |k, v| [k.to_s.capitalize, v] } puts Terminal::Table.new rows: rows end |
.print_single_value(total) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/moneymanager/layout.rb', line 31 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 |