From: Charles McGarvey Date: Sun, 18 Aug 2019 17:51:12 +0000 (-0600) Subject: add support for formatting metadata X-Git-Tag: v0.006~2 X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=07329500b7d9a2e8fcfd9eb97f485deaea9f48f7;p=chaz%2Fhomebank2ledger add support for formatting metadata --- diff --git a/lib/App/HomeBank2Ledger/Formatter/Beancount.pm b/lib/App/HomeBank2Ledger/Formatter/Beancount.pm index 659283a..748a0bf 100644 --- a/lib/App/HomeBank2Ledger/Formatter/Beancount.pm +++ b/lib/App/HomeBank2Ledger/Formatter/Beancount.pm @@ -16,6 +16,7 @@ use warnings; use strict; use App::HomeBank2Ledger::Util qw(commify rtrim); +use Scalar::Util qw(looks_like_number); use parent 'App::HomeBank2Ledger::Formatter'; @@ -197,6 +198,13 @@ sub _format_transaction { $out[-1] .= ' '.join(' ', @tags); } + my $metadata = $transaction->{metadata} || {}; + for my $key (sort keys %$metadata) { + my $value = looks_like_number($metadata->{$key}) ? $metadata->{$key} + : $self->_format_string($metadata->{$key}); + push @out, " ; ${key}: ${value}"; + } + for my $posting (@postings) { my @line; @@ -233,6 +241,13 @@ sub _format_transaction { } push @out, join('', @line); + + my $metadata = $posting->{metadata} || {}; + for my $key (sort keys %$metadata) { + my $value = looks_like_number($metadata->{$key}) ? $metadata->{$key} + : $self->_format_string($metadata->{$key}); + push @out, " ; ${key}: ${value}"; + } } push @out, ''; diff --git a/lib/App/HomeBank2Ledger/Formatter/Ledger.pm b/lib/App/HomeBank2Ledger/Formatter/Ledger.pm index 8f05441..464fa04 100644 --- a/lib/App/HomeBank2Ledger/Formatter/Ledger.pm +++ b/lib/App/HomeBank2Ledger/Formatter/Ledger.pm @@ -234,6 +234,12 @@ sub _format_transaction { $memo && " ; $memo", ); + my $metadata = $transaction->{metadata} || {}; + for my $key (sort keys %$metadata) { + my $value = $self->_format_string($metadata->{$key}); + push @out, " ; ${key}: ${value}"; + } + for my $posting (@postings) { my @line; @@ -271,6 +277,12 @@ sub _format_transaction { push @out, join('', @line); + my $metadata = $posting->{metadata} || {}; + for my $key (sort keys %$metadata) { + my $value = $self->_format_string($metadata->{$key}); + push @out, " ; ${key}: ${value}"; + } + if (my $posting_payee = $posting->{payee}) { $posting_payee = $self->_format_string($posting_payee); push @out, " ; Payee: $posting_payee" if $posting_payee ne $payee;