X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fhomebank2ledger;a=blobdiff_plain;f=lib%2FApp%2FHomeBank2Ledger%2FFormatter%2FLedger.pm;h=3a5a71379b6d6941f58c70e47793ed1e9c43c718;hp=e4ecb2a177c89daca2f22334f9cd6ae026ee364c;hb=5047b75a7e4c5df848f343c46d732643c27f8882;hpb=d96646d72e6ef66b272e789963f73f91369394a0 diff --git a/lib/App/HomeBank2Ledger/Formatter/Ledger.pm b/lib/App/HomeBank2Ledger/Formatter/Ledger.pm index e4ecb2a..3a5a713 100644 --- a/lib/App/HomeBank2Ledger/Formatter/Ledger.pm +++ b/lib/App/HomeBank2Ledger/Formatter/Ledger.pm @@ -49,7 +49,8 @@ sub format { Get formatted header. For example, - ; Converted from finances.xhb using homebank2ledger 0.001 + ; Name: My Finances + ; File: path/to/finances.xhb =cut @@ -61,9 +62,9 @@ sub format_header { if (my $name = $self->name) { push @out, "; Name: $name"; } - - my $file = $self->file; - push @out, "; Converted from ${file} using homebank2ledger ${VERSION}"; + if (my $file = $self->file) { + push @out, "; File: $file"; + } push @out, ''; @@ -247,12 +248,13 @@ sub _format_transaction { push @out, join('', @line); - if (my $payee = $posting->{payee}) { - push @out, ' ; Payee: '.$self->_format_string($payee); + if (my $posting_payee = $posting->{payee}) { + $posting_payee = $self->_format_string($posting_payee); + push @out, " ; Payee: $posting_payee" if $posting_payee ne $payee; } if (my @tags = @{$posting->{tags} || []}) { - push @out, " ; :".join(':', @tags).":"; + push @out, ' ; :'.join(':', @tags).':'; } } @@ -268,6 +270,13 @@ sub _format_string { return $str; } +sub _quote_string { + my $self = shift; + my $str = shift; + $str =~ s/"/\\"/g; + return "\"$str\""; +} + sub _format_amount { my $self = shift; my $amount = shift; @@ -278,7 +287,10 @@ sub _format_amount { my $num = join($commodity->{dchar}, commify($whole, $commodity->{gchar}), $fraction); - $num = $commodity->{syprf} ? "$commodity->{symbol} $num" : "$num $commodity->{symbol}"; + my $symbol = $commodity->{symbol}; + $symbol = $self->_quote_string($symbol) if $symbol =~ /[0-9\s]/; + + $num = $commodity->{syprf} ? "$symbol $num" : "$num $symbol"; return $num; }