]> Dogcows Code - chaz/homebank2ledger/commitdiff
add file_version method to File::HomeBank
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sat, 2 May 2020 19:00:45 +0000 (13:00 -0600)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sat, 2 May 2020 19:00:45 +0000 (13:00 -0600)
lib/File/HomeBank.pm

index 7d29ada68dfa09d4acc4459090b60af58ec6bfc2..004e768de3a3377a79d9af975b97f13a7fd9825b 100644 (file)
@@ -152,6 +152,18 @@ sub file {
     shift->{file};
 }
 
+=method file_version
+
+    $version = $homebank->file_version;
+
+Get the file format version.
+
+=cut
+
+sub file_version {
+    shift->{homebank}{version};
+}
+
 =method title
 
     $title = $homebank->title;
@@ -226,7 +238,7 @@ sub tags {
 
     $account = $homebank->find_account_by_key($key);
 
-Find a account with the given key.
+Find an account with the given key.
 
 =cut
 
@@ -520,6 +532,7 @@ Parse a HomeBank file from a string.
 sub parse_string {
     my $str = shift or die _usage(q{parse_string($str)});
 
+    my %homebank;
     my %properties;
     my @accounts;
     my @payees;
@@ -539,7 +552,11 @@ sub parse_string {
                     $attr{$key} = _decode_xml_entities($attr{$key});
                 }
 
-                if ($node eq 'properties') {
+                if ($node eq 'homebank') {
+                    $attr{version} = delete $attr{v} if $attr{v};
+                    %homebank = %attr;
+                }
+                elsif ($node eq 'properties') {
                     $attr{currency} = delete $attr{curr} if $attr{curr};
                     %properties = %attr;
                 }
@@ -605,6 +622,7 @@ sub parse_string {
     $xml_parser->parse($str);
 
     return {
+        homebank        => \%homebank,
         properties      => \%properties,
         accounts        => \@accounts,
         payees          => \@payees,
This page took 0.029255 seconds and 4 git commands to generate.