X-Git-Url: http://git.cascardo.info/?p=cascardo%2FFinance-Bank-BR-Santander-Spreadsheet.git;a=blobdiff_plain;f=lib%2FFinance%2FBank%2FBR%2FSantander%2FSpreadsheet.pm;h=e388aeb0b8dd0488f8b25552f4ca1d62663bd120;hp=c48062be9427cfff55ed7a7c3f1c8a18c7a20fb3;hb=14ed6af8e07188102dc430663bafe79a38ef30e1;hpb=d242e79c42586081300f37be1b66e5502bae3ca9 diff --git a/lib/Finance/Bank/BR/Santander/Spreadsheet.pm b/lib/Finance/Bank/BR/Santander/Spreadsheet.pm index c48062b..e388aeb 100644 --- a/lib/Finance/Bank/BR/Santander/Spreadsheet.pm +++ b/lib/Finance/Bank/BR/Santander/Spreadsheet.pm @@ -3,20 +3,6 @@ package Finance::Bank::BR::Santander::Spreadsheet; use strict; use warnings; -=head1 COPYRIGHT AND LICENSE - - Copyright (C) 2015 Thadeu Lima de Souza Cascardo - - This program is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License; either version 2 of the License, - or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. - -=cut - use Spreadsheet::ParseExcel::Simple; use DateTime::Format::Strptime qw(strptime); @@ -28,7 +14,9 @@ sub new { my $self = {}; bless $self, $class; $self->_init; - $self->load(@_); + if ($self->load(@_)) { + return undef; + } return $self; } @@ -66,10 +54,11 @@ sub load { if (defined($filename)) { my $xls = Spreadsheet::ParseExcel::Simple->read($filename); if (!defined($xls)) { - return; + return 1; } $self->_parse($xls); } + return 0; } sub balance { @@ -83,3 +72,78 @@ sub statement { } 1; + +__END__ + +=head1 NAME + +Finance::Bank::BR::Santander::Spreadsheet - Parse statement exported from Brazilian branch of Santander Internet Banking + +=head1 SYNOPSIS + + use Finance::Bank::BR::Santander::Spreadsheet; + + my $spreadsheet = Finance::Bank::BR::Santander::Spreadsheet->new($filename); + my $balance = $spreadsheet->balance; + my $data = $spreadsheet->statement; + foreach my $transaction (@{$data}) { + say "$transaction->{date}, $transaction->{name}, $transaction->{extra}, $transaction->{value}, $transaction->{balance}"; + } + +=head1 Description + +This module is an object-oriented interface that parses statements exported as XLS from the Internet Banking for the Brazilian branch of Santander. + +=head1 Spreadsheet + +=head2 new($filename) + +The C method creates a new Spreadsheet object containing the data parsed from C<$filename>. + +If an error occurs while loading the file, C returns C. + +=head2 balance() + +The C method returns the last balance found in the sheet. + +=head2 statement() + +The C method returns a reference to an array of transactions, described as below. + +=head1 Transaction + +The transaction is a hash containing the following keys: + +=head2 name + +A string with a name describing the transaction. + +=head2 value + +A floating number containing the credit (positive) or debit (negative) of the transaction. + +=head2 date + +A DateTime object representing the date when the transaction occurred. + +=head2 balance + +A floating number containing the balance resulting from the transaction. + +=head2 extra + +Data provided by the bank identifying the transaction. In this case, a number specific to the type of transaction. It can be used to help uniquely identify the transaction. + +=head1 COPYRIGHT AND LICENSE + + Copyright (C) 2015 Thadeu Lima de Souza Cascardo + + This program is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License; either version 2 of the License, + or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. + +=cut