]> Dogcows Code - chaz/homebank2ledger/blobdiff - lib/App/HomeBank2Ledger/Formatter/Ledger.pm
simplify header in output
[chaz/homebank2ledger] / lib / App / HomeBank2Ledger / Formatter / Ledger.pm
index e4ecb2a177c89daca2f22334f9cd6ae026ee364c..3a5a71379b6d6941f58c70e47793ed1e9c43c718 100644 (file)
@@ -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;
 }
This page took 0.017818 seconds and 4 git commands to generate.