X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fhomebank2ledger;a=blobdiff_plain;f=lib%2FApp%2FHomeBank2Ledger%2FFormatter%2FBeancount.pm;h=748a0bf31ecdcfd2dd71edc413eefc8dd5f512a3;hp=659283a389e54ca4d6239f8a60c2272cf1645385;hb=07329500b7d9a2e8fcfd9eb97f485deaea9f48f7;hpb=5d744d0c10798b501b6d5de662794fb7e14f3242 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, '';