mercury_banking 0.5.36 → 0.5.37

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: d911a07f674d64b6c7f51721e61f6206bf8df0617a2ff49359fe60b0c21bfd67
4
+ data.tar.gz: 38ea8c7134a967578e272a579f584551aee9291704d801334282f668a92c9650
5
5
  SHA512:
6
- metadata.gz: 5684f7edb49b46b8d0a2629fa1f5a8fcd3deff88f82fc4c30b20226eb54d300b78df9e86e153d0a0e75eace6befa9465b1adaa5c1e4b366cfc4ef098356fd76d
7
- data.tar.gz: 8673739e687274aaa9cc7c81d5fa3346eb8b68d76a48e60502db9572ff1986c654f9323215a91c0ee8590d1cb414471140524d9b82ca11fecdedf4a4a08bc2a3
6
+ metadata.gz: e3c9026d8ddf19000481a2ade598537f0d8d499941e789c47615bdace60b90f96ba38928f4ba8ada644966cefb9458a3ece9d15b1f1743a46e0b6b4790eee45f
7
+ data.tar.gz: efd73dbe4b0020e26e235775dab67d1b728ca545404ddb6471020d1e75f21139e670ec045222538a51df49e45a5777afad1e31c9e1729ad1d20a804dadd896e9
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.37)
5
5
  activesupport (~> 7.0.0)
6
6
  dotenv (~> 2.8)
7
7
  fiddle (~> 1.1)
@@ -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.37"
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.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Siegel