Module: MercuryBanking::Formatters::TableFormatter
- Included in:
- CLI::Main
- Defined in:
- lib/mercury_banking/formatters/table_formatter.rb
Overview
Formatter for table output
Instance Method Summary collapse
-
#display_accounts_table(accounts) ⇒ Object
Display accounts in a table format.
-
#display_recipients_table(recipients) ⇒ Object
Display recipients in a table format.
-
#display_transaction_details(transaction) ⇒ Object
Display a single transaction’s details.
-
#display_transactions_table(transactions, show_account_name = false) ⇒ Object
Display transactions in a table format.
Instance Method Details
#display_accounts_table(accounts) ⇒ Object
Display accounts in a table format
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mercury_banking/formatters/table_formatter.rb', line 8 def display_accounts_table(accounts) return puts "No accounts found." if accounts.empty? rows = accounts.map do |a| [ a["name"], a["accountNumber"], a["kind"].capitalize, format("$%.2f", a["currentBalance"]), format("$%.2f", a["availableBalance"]), a["status"].capitalize ] end table = ::Terminal::Table.new( headings: ['Account Name', 'Account Number', 'Type', 'Current Balance', 'Available Balance', 'Status'], rows: rows ) puts table end |
#display_recipients_table(recipients) ⇒ Object
Display recipients in a table format
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mercury_banking/formatters/table_formatter.rb', line 31 def display_recipients_table(recipients) return puts "No recipients found." if recipients.empty? rows = recipients.map do |r| account_info = r["electronicRoutingInfo"] || {} address_info = r["address"] || {} [ r["id"], r["name"], account_info["routingNumber"] || "N/A", mask_account_number(account_info["accountNumber"]), address_info["city"] || "N/A", r["status"].capitalize ] end table = ::Terminal::Table.new( headings: ['ID', 'Name', 'Routing #', 'Account #', 'City', 'Status'], rows: rows ) puts table end |
#display_transaction_details(transaction) ⇒ Object
Display a single transaction’s details
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/mercury_banking/formatters/table_formatter.rb', line 86 def display_transaction_details(transaction) return puts "Transaction not found." unless transaction # Format dates created_at = transaction["createdAt"] ? Time.parse(transaction["createdAt"]).strftime("%Y-%m-%d %H:%M:%S") : "N/A" posted_at = transaction["postedAt"] ? Time.parse(transaction["postedAt"]).strftime("%Y-%m-%d %H:%M:%S") : "Pending" estimated_delivery = transaction["estimatedDeliveryDate"] ? Time.parse(transaction["estimatedDeliveryDate"]).strftime("%Y-%m-%d") : "N/A" # Format amount amount = transaction["amount"].to_f amount_str = format("$%.2f", amount.abs) direction = amount.negative? ? "DEBIT" : "CREDIT" # Get counterparty info counterparty = transaction["counterpartyId"] ? "ID: #{transaction['counterpartyId']}" : "N/A" # Create a table for the transaction details details = [ ["Transaction ID", transaction["id"]], ["Amount", "#{amount_str} (#{direction})"], ["Status", transaction["status"].capitalize], ["Created At", created_at], ["Posted At", posted_at], ["Estimated Delivery", estimated_delivery], ["Description", transaction["bankDescription"] || "N/A"], ["Note", transaction["note"] || "N/A"], ["External Memo", transaction["externalMemo"] || "N/A"], ["Counterparty", counterparty] ] table = ::Terminal::Table.new( title: "Transaction Details", rows: details ) puts table end |
#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 |