mercury_banking 0.5.36 → 0.5.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a204ef3a88607de2674a812b67b13aca1c3d55ab5ce30898e291386f35d2100a
4
- data.tar.gz: 74577f4d37da40c2b542e653883e6ac0564c0d755e17f5c63cfef55729dbc946
3
+ metadata.gz: fd83aeec4085d1c49fe77f7ca68fbc0b7c215dc37deafba3b36a20da0e7f46c4
4
+ data.tar.gz: 102b6b607353df20f4494c758935fe3f3517a2a4c95fca8440f9598b364d4f71
5
5
  SHA512:
6
- metadata.gz: 5684f7edb49b46b8d0a2629fa1f5a8fcd3deff88f82fc4c30b20226eb54d300b78df9e86e153d0a0e75eace6befa9465b1adaa5c1e4b366cfc4ef098356fd76d
7
- data.tar.gz: 8673739e687274aaa9cc7c81d5fa3346eb8b68d76a48e60502db9572ff1986c654f9323215a91c0ee8590d1cb414471140524d9b82ca11fecdedf4a4a08bc2a3
6
+ metadata.gz: 06a9d7eea59264a65f07ef4073189c390b8b0d025bdbeced8af797d06f67066e14cd704db814ad61ebaedd03c0682171a5604b2be295463751808b2ddc2057b5
7
+ data.tar.gz: b4898456ae09b4cceb0bf6a23c01fe7f860073fd76d069f1b70c0e5a4fc8c266ce52999351dfc319178730cea7779c9649076c43398604aaeadf9824ce9d8d49
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mercury_banking (0.5.36)
4
+ mercury_banking (0.5.38)
5
5
  activesupport (~> 7.0.0)
6
6
  dotenv (~> 2.8)
7
7
  fiddle (~> 1.1)
@@ -112,6 +112,7 @@ module MercuryBanking
112
112
  account_transactions.each do |transaction|
113
113
  transaction["accountName"] = account["name"]
114
114
  transaction["accountId"] = account["id"]
115
+ transaction["accountNumber"] = account["accountNumber"]
115
116
  end
116
117
  all_transactions.concat(account_transactions)
117
118
  rescue StandardError => e
@@ -27,7 +27,7 @@ module MercuryBanking
27
27
  end_date = options[:end_date]
28
28
 
29
29
  # Get format
30
- format = options[:format]
30
+ format = options[:format] || 'all'
31
31
 
32
32
  # Get verbose option
33
33
  verbose = options[:verbose]
@@ -36,12 +36,20 @@ module MercuryBanking
36
36
  accounts.each do |account|
37
37
  account_id = account["id"]
38
38
  account_name = account["name"]
39
+ account_number = account["accountNumber"]
39
40
 
40
41
  puts "Fetching transactions for #{account_name} (#{account_id})..."
41
42
 
42
43
  # Get all transactions for this account
43
44
  transactions = client.get_transactions(account_id, start_date)
44
45
 
46
+ # Add account information to each transaction
47
+ transactions.each do |transaction|
48
+ transaction["accountName"] = account_name
49
+ transaction["accountId"] = account_id
50
+ transaction["accountNumber"] = account_number
51
+ end
52
+
45
53
  # Filter by end date if specified
46
54
  if end_date
47
55
  end_date_obj = Date.parse(end_date)
@@ -135,6 +143,13 @@ module MercuryBanking
135
143
  puts "Fetching transactions for #{account["name"]}..."
136
144
  transactions = client.get_transactions(account_id, start_date)
137
145
 
146
+ # Add account information to each transaction
147
+ transactions.each do |transaction|
148
+ transaction["accountName"] = account["name"]
149
+ transaction["accountId"] = account["id"]
150
+ transaction["accountNumber"] = account["accountNumber"]
151
+ end
152
+
138
153
  # Filter by end date if specified
139
154
  if end_date
140
155
  end_date_obj = Date.parse(end_date)
@@ -461,12 +461,27 @@ module MercuryBanking
461
461
  end
462
462
 
463
463
  def write_ledger_account_declarations(file, transactions)
464
- # Get unique account names from transactions
465
- account_names = transactions.map { |t| t["accountName"] || "Unknown Account" }.uniq
464
+ # Get unique accounts from transactions
465
+ accounts = transactions.map do |t|
466
+ {
467
+ "name" => t["accountName"] || "Unknown Account",
468
+ "number" => t["accountNumber"]
469
+ }
470
+ end.uniq { |a| [a["name"], a["number"]] }
466
471
 
467
472
  # Define accounts dynamically based on transaction data
468
- account_names.each do |account_name|
469
- file.puts "account Assets:#{account_name}"
473
+ accounts.each do |account|
474
+ account_name = account["name"]
475
+ account_number = account["number"]
476
+
477
+ # Format the account name to include the account number if available
478
+ formatted_account_name = if account_number
479
+ "#{account_name} #{account_number.to_s[-4..-1]}"
480
+ else
481
+ account_name
482
+ end
483
+
484
+ file.puts "account Assets:#{formatted_account_name}"
470
485
  end
471
486
  file.puts "account Expenses:Unknown"
472
487
  file.puts "account Income:Unknown"
@@ -490,23 +505,31 @@ module MercuryBanking
490
505
  description = transaction["bankDescription"] || transaction["externalMemo"] || "Unknown transaction"
491
506
  amount = transaction["amount"]
492
507
  account_name = transaction["accountName"] || "Unknown Account"
508
+ account_number = transaction["accountNumber"]
493
509
 
494
510
  file.puts "#{date} #{description}"
495
511
  file.puts " ; Transaction ID: #{transaction["id"]}"
496
512
  file.puts " ; Status: #{transaction["status"]}"
497
513
  file.puts " ; Reconciled: No"
498
514
 
499
- write_ledger_postings(file, amount, account_name)
515
+ write_ledger_postings(file, amount, account_name, account_number)
500
516
  file.puts
501
517
  end
502
518
 
503
- def write_ledger_postings(file, amount, account_name)
519
+ def write_ledger_postings(file, amount, account_name, account_number = nil)
520
+ # Format the account name to include the account number if available
521
+ formatted_account_name = if account_number
522
+ "#{account_name} #{account_number.to_s[-4..-1]}"
523
+ else
524
+ account_name
525
+ end
526
+
504
527
  if amount > 0
505
528
  file.puts " Income:Unknown $-#{format("%.2f", amount)}"
506
- file.puts " Assets:#{account_name} $#{format("%.2f", amount)}"
529
+ file.puts " Assets:#{formatted_account_name} $#{format("%.2f", amount)}"
507
530
  else
508
531
  file.puts " Expenses:Unknown $#{format("%.2f", amount.abs)}"
509
- file.puts " Assets:#{account_name} $-#{format("%.2f", amount.abs)}"
532
+ file.puts " Assets:#{formatted_account_name} $-#{format("%.2f", amount.abs)}"
510
533
  end
511
534
  end
512
535
 
@@ -529,14 +552,30 @@ module MercuryBanking
529
552
  end
530
553
 
531
554
  def write_beancount_account_declarations(file, transactions)
532
- # Get unique account names from transactions
533
- account_names = transactions.map { |t| t["accountName"] || "Unknown Account" }.uniq
555
+ # Get unique accounts from transactions
556
+ accounts = transactions.map do |t|
557
+ {
558
+ "name" => t["accountName"] || "Unknown Account",
559
+ "number" => t["accountNumber"]
560
+ }
561
+ end.uniq { |a| [a["name"], a["number"]] }
534
562
 
535
563
  # Define accounts dynamically based on transaction data
536
- account_names.each do |account_name|
564
+ accounts.each do |account|
565
+ account_name = account["name"]
566
+ account_number = account["number"]
567
+
537
568
  # Sanitize account name for beancount format
538
569
  safe_account_name = account_name.gsub(/[^a-zA-Z0-9]/, '-')
539
- file.puts "1970-01-01 open Assets:#{safe_account_name}"
570
+
571
+ # Format the account name to include the account number if available
572
+ formatted_account_name = if account_number
573
+ "#{safe_account_name}-#{account_number.to_s[-4..-1]}"
574
+ else
575
+ safe_account_name
576
+ end
577
+
578
+ file.puts "1970-01-01 open Assets:#{formatted_account_name}"
540
579
  end
541
580
  file.puts "1970-01-01 open Expenses:Unknown"
542
581
  file.puts "1970-01-01 open Income:Unknown"
@@ -560,6 +599,8 @@ module MercuryBanking
560
599
  description = transaction["bankDescription"] || transaction["externalMemo"] || "Unknown transaction"
561
600
  amount = transaction["amount"]
562
601
  account_name = transaction["accountName"] || "Unknown Account"
602
+ account_number = transaction["accountNumber"]
603
+
563
604
  # Sanitize account name for beancount format
564
605
  safe_account_name = account_name.gsub(/[^a-zA-Z0-9]/, '-')
565
606
 
@@ -568,17 +609,24 @@ module MercuryBanking
568
609
  file.puts " ; Status: #{transaction["status"]}"
569
610
  file.puts " ; Reconciled: No"
570
611
 
571
- write_beancount_postings(file, amount, safe_account_name)
612
+ write_beancount_postings(file, amount, safe_account_name, account_number)
572
613
  file.puts
573
614
  end
574
615
 
575
- def write_beancount_postings(file, amount, account_name)
616
+ def write_beancount_postings(file, amount, account_name, account_number = nil)
617
+ # Format the account name to include the account number if available
618
+ formatted_account_name = if account_number
619
+ "#{account_name}-#{account_number.to_s[-4..-1]}"
620
+ else
621
+ account_name
622
+ end
623
+
576
624
  if amount > 0
577
625
  file.puts " Income:Unknown -#{format("%.2f", amount)} USD"
578
- file.puts " Assets:#{account_name} #{format("%.2f", amount)} USD"
626
+ file.puts " Assets:#{formatted_account_name} #{format("%.2f", amount)} USD"
579
627
  else
580
628
  file.puts " Expenses:Unknown #{format("%.2f", amount.abs)} USD"
581
- file.puts " Assets:#{account_name} -#{format("%.2f", amount.abs)} USD"
629
+ file.puts " Assets:#{formatted_account_name} -#{format("%.2f", amount.abs)} USD"
582
630
  end
583
631
  end
584
632
  end
@@ -1,3 +1,3 @@
1
1
  module MercuryBanking
2
- VERSION = "0.5.36"
2
+ VERSION = "0.5.38"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mercury_banking
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.36
4
+ version: 0.5.38
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Siegel