]> Dogcows Code - chaz/homebank2ledger/blobdiff - lib/App/HomeBank2Ledger/Formatter/Ledger.pm
simplify header in output
[chaz/homebank2ledger] / lib / App / HomeBank2Ledger / Formatter / Ledger.pm
index 677facb02e72a5924617ca4e726424921d9497f7..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, '';
 
@@ -269,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;
@@ -279,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.017744 seconds and 4 git commands to generate.