Method: MercuryBanking::Formatters::TableFormatter#display_transactions_table
- Defined in:
- lib/mercury_banking/formatters/table_formatter.rb
#display_transactions_table(transactions, show_account_name = false) ⇒ Object
Display transactions in a table format
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/mercury_banking/formatters/table_formatter.rb', line 57 def display_transactions_table(transactions, show_account_name = false) return puts "No transactions found." if transactions.empty? headings = %w[Date Amount Type] headings.insert(0, 'Account') if show_account_name headings.push("Description", "Status") rows = transactions.map do |t| date = t["postedAt"] ? Time.parse(t["postedAt"]).strftime("%Y-%m-%d") : "Pending" amount = format("$%.2f", t["amount"].abs) direction = (t["amount"]).negative? ? "DEBIT" : "CREDIT" description = t["bankDescription"] || t["externalMemo"] || "N/A" description = description.length > 50 ? "#{description[0..47]}..." : description status = t["status"].capitalize row = [date, amount, direction, description, status] row.insert(0, t["accountName"]) if show_account_name row end table = ::Terminal::Table.new( headings: headings, rows: rows ) puts table end |