File Coverage

lib/Finance/Bank/SentinelBenefits/Csv401kConverter/LineParser.pm
Criterion Covered Total %
statement 28 28 100.0
branch 10 10 100.0
condition 3 3 100.0
subroutine 7 7 100.0
pod 1 1 100.0
total 49 49 100.0


line stmt bran cond sub pod time code
1             package Finance::Bank::SentinelBenefits::Csv401kConverter::LineParser;
2             $Finance::Bank::SentinelBenefits::Csv401kConverter::LineParser::VERSION = '1.3';
3 6     6   3614 use Modern::Perl;
  6         12  
  6         58  
4             =head1 NAME
5              
6             Finance::Bank::SentinelBenefits::Csv401kConverter::LineParser - turns
7             CSV lines into standardized Line objects
8              
9             =head1 VERSION
10              
11             version 1.3
12              
13             =head1 SYNOPSIS
14              
15              
16              
17             This class takes raw lines from the Sentinel website's CSV files and a map
18             of security names to symbols, and returns parsed C<Finance::Bank::SentinelBenefits::Csv401kConverter::Line>
19             objects
20              
21              
22              
23             =cut
24              
25 6     6   2491 use Moose;
  6         917537  
  6         50  
26              
27 6     6   44776 use Finance::Bank::SentinelBenefits::Csv401kConverter::SymbolMap;
  6         18  
  6         189  
28 6     6   3432 use Finance::Bank::SentinelBenefits::Csv401kConverter::Line;
  6         2505  
  6         335  
29              
30              
31             =head1 CONSTANTS
32              
33             =head2 NUMBER_OF_FIELDS
34              
35             Number of fields in the Sentinel file
36              
37             =cut
38             use constant {
39 6         2243 NUMBER_OF_FIELDS => 7,
40 6     6   66 };
  6         19  
41              
42             =head1 Constructor
43              
44              
45              
46             =head2 new()
47              
48              
49              
50             my $f = Finance::Bank::SentinelBenefits::Csv401kConverter::LineParser->new( {
51             symbol_map => $symbol_map,
52             } );
53              
54             Construct a new LineParser with the given symbol map
55              
56              
57              
58             =head1 Accessors
59              
60              
61              
62             =head2 $p->symbol_map()
63              
64              
65              
66             Accesses the passed in symbol map. This is only really for internal
67             use, as the symbol map is immutable.
68              
69              
70              
71             =cut
72              
73             has 'symbol_map' => (
74             is => 'ro',
75             isa => 'Finance::Bank::SentinelBenefits::Csv401kConverter::SymbolMap',
76             required => 1,
77             );
78              
79             =head1 Methods
80              
81              
82              
83             =head2 $f->parse_line($line);
84              
85              
86              
87             This method takes the line to be parsed as an argument.
88              
89              
90              
91             If it is a valid security line, it returns a C<Finance::Bank::SentinelBenefits::Csv401kConverter::Line>.
92              
93              
94              
95             If it is not a valid security line, it returns C<undef>.
96              
97              
98              
99             =cut
100              
101             sub parse_line {
102 66     66 1 13498 my $self = shift;
103 66         185 my $line = shift;
104 66         92 my $date = shift;
105              
106 66         278 my @line_parts = split /,/, $line;
107              
108 66 100 100     446 if(NUMBER_OF_FIELDS() == @line_parts
109             && $line_parts[0] =~ m/Employe. .+ Contribution/){
110            
111 34         118 my ($contribution_type, $status, $memo, $quantity, $price, $total, $redemption_fee) = @line_parts;
112              
113 34         94 $total =~ s/\$//;
114              
115 34 100       1405 my $parsed_line = Finance::Bank::SentinelBenefits::Csv401kConverter::Line->new( {
    100          
    100          
    100          
116             date => $date,
117             symbol => $self->symbol_map()->get_symbol($memo),
118             memo => $memo,
119             quantity => abs($quantity),
120             price => $price,
121             total => abs($total),
122             side => $memo =~ m/^Sell/ ? 'Sell'
123             : $memo =~ m/^Gain\/Loss/ ? 'ReinvDiv'
124             : $memo =~ m/^Dividend/ ? 'ReinvDiv'
125             : 'Buy',
126             source => $contribution_type =~ m/Employer Matching Contribution/ ? 'Match' : 'Deferral',
127             } );
128 34         244 return $parsed_line;
129             }
130              
131 32         103 return;
132             }
133              
134 6     6   50 no Moose;
  6         17  
  6         46  
135              
136             __PACKAGE__->meta->make_immutable;
137              
138              
139             =head1 LICENSE AND COPYRIGHT
140             Copyright 2009-2023 David Solimano
141             This file is part of Finance::Bank::SentinelBenefits::Csv401kConverter
142              
143             Finance::Bank::SentinelBenefits::Csv401kConverter is free software: you can redistribute it and/or modify
144             it under the terms of the GNU General Public License as published by
145             the Free Software Foundation, either version 3 of the License, or
146             (at your option) any later version.
147              
148             Finance::Bank::SentinelBenefits::Csv401kConverter is distributed in the hope that it will be useful,
149             but WITHOUT ANY WARRANTY; without even the implied warranty of
150             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
151             GNU General Public License for more details.
152              
153             You should have received a copy of the GNU General Public License
154             along with Finance::Bank::SentinelBenefits::Csv401kConverter. If not, see <http://www.gnu.org/licenses/>
155              
156             =cut