use XML::Entities;
use XML::Parser::Lite;
-our $VERSION = '0.007'; # VERSION
+our $VERSION = '0.010'; # VERSION
our @EXPORT_OK = qw(parse_string parse_file);
}
+sub file_version {
+ shift->{homebank}{version};
+}
+
+
sub title {
shift->{properties}{title};
}
my $self = shift;
my $transaction = shift;
- return if $transaction->{paymode} ne 'internaltransfer';
+ return if !$transaction->{dst_account};
my $transfer_key = $transaction->{transfer_key};
my @candidates;
for my $t (@{$self->transactions}) {
- next if $t->{paymode} ne 'internaltransfer';
+ next if !$t->{dst_account};
next if $t->{account} != $transaction->{dst_account};
next if $t->{dst_account} != $transaction->{account};
next if $t->{amount} != -$transaction->{amount};
# sort the candidates so we can pick the nearest one by date
my @ordered_candidates =
- map { $_->[1] }
+ map { $_->[1] }
sort { $a->[0] <=> $b->[0] }
- map { [abs($transaction_day - _ymd_to_julian($_->{date})), $_] } @candidates;
+ map { [abs($transaction_day - _ymd_to_julian($_->{date})), $_] } @candidates;
if (my $winner = $ordered_candidates[0]) {
my $key1 = $transfer_key || '[no key]';
sub parse_string {
my $str = shift or die _usage(q{parse_string($str)});
+ my %homebank;
my %properties;
my @accounts;
my @payees;
$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;
}
$xml_parser->parse($str);
return {
+ homebank => \%homebank,
properties => \%properties,
accounts => \@accounts,
payees => \@payees,
=head1 VERSION
-version 0.007
+version 0.010
=head1 SYNOPSIS
Construct a L<File::HomeBank>.
+=head2 file_version
+
+ $version = $homebank->file_version;
+
+Get the file format version.
+
=head2 title
$title = $homebank->title;
$account = $homebank->find_account_by_key($key);
-Find a account with the given key.
+Find an account with the given key.
=head2 find_currency_by_key