Class: Layout
- Inherits:
-
Object
- Object
- Layout
- Defined in:
- lib/moneymanager/layout.rb
Class Method Summary collapse
- .clear ⇒ Object
- .formatted_amount(amount) ⇒ Object
- .print_multiple(entries) ⇒ Object
- .print_single(entry) ⇒ Object
- .print_summary(income, expenses) ⇒ Object
Class Method Details
.clear ⇒ Object
43 44 45 |
# File 'lib/moneymanager/layout.rb', line 43 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_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_summary(income, expenses) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/moneymanager/layout.rb', line 31 def self.print_summary(income, expenses) delta = income + expenses table = Terminal::Table.new do |t| t << ['Income', formatted_amount(income)] t << ['Expense', formatted_amount(expenses)] t << ['Delta', formatted_amount(delta)] end table.align_column(1, :right) table.title = "Summary" puts table end |