Finance::Wesabe::Account - Class to represent a wesabe account


Finance-Wesabe documentation Contained in the Finance-Wesabe distribution.

Index


Code Index:

NAME

Top

Finance::Wesabe::Account - Class to represent a wesabe account

SYNOPSIS

Top

    my $account = Finance::Wesabe::Account->new(
        content => $c, parent => $p
    );

DESCRIPTION

Top

This modules provides access to your basic account information, including individual transactions.

ACCESSORS

Top

* content - Hashref of data from the response
* parent - Parent object with acces to the user agent

ACCOUNT INFORMATION

Top

* name
* id
* guid
* txaction_count
* account_type
* account_number
* newest_txaction - A DateTime object
* oldest_txaction - A DateTime object
* last_uploaded_at - A DateTime object
* balance

METHODS

Top

transactions( )

Returns a list of Finance::Wesabe::Transaction objects for transactions associated with this account.

pretty_balance( )

Returns your balance in a nicely formatted string based on your preferenes.

AUTHOR

Top

Brian Cassidy <bricas@cpan.org>

COPYRIGHT AND LICENSE

Top


Finance-Wesabe documentation Contained in the Finance-Wesabe distribution.
package Finance::Wesabe::Account;

use Moose;
use Finance::Wesabe::Utils;
use Finance::Wesabe::Transaction;

has content => ( is => 'ro', isa => 'HashRef' );

has parent => ( is => 'ro', isa => 'Object' );

__PACKAGE__->mk_simple_field( qw( name txaction-count account-type account-number id guid ) );
__PACKAGE__->mk_deep_date_field( qw( newest-txaction oldest-txaction last-uploaded-at ) );
__PACKAGE__->mk_deep_field_map( ( 'current-balance' => 'balance' ) );

sub transactions {
    my $self = shift;

    if( !$self->{content}->{txactions} ) {
        return $self->parent->account( $self->content->{ id } )->transactions;
    }

    return map { Finance::Wesabe::Transaction->new( content => $_, parent => $self )  } @{ $self->{content}->{txactions}->{txaction} };
}

sub pretty_balance {
    my $self = shift;
    return $self->_format_number( $self->balance );
}

sub _format_number {
    my( $self, $number ) = @_;
    my( $sign, $whole, $frac ) = $number =~ m{^([+-]?)(\d+)\.(\d+)};
    $sign ||= '';

    my $currency = $self->content->{ currency };
    my $del = $currency->{delimiter};
    1 while $whole =~ s{(\d)(\d\d\d)(?!\d)}{$1$del$2}g;

    my $places = $currency->{decimal_places};
    $frac = sprintf( "%0${places}d", $frac );

    my $sep = $currency->{separator};
    my $sym = $currency->{ symbol };
    return "$sign$sym$whole$sep$frac " . $currency->{content};
}

no Moose;

__PACKAGE__->meta->make_immutable;

1;