blib/lib/Finance/Bank/SentinelBenefits/Csv401kConverter/LineParser.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 53 CC 6 SCAR 30.9
CC
6
Cov
0%
parse_line
42.0
BEGIN
2.0
BEGIN
2.0
CRAP 22.0
1 package Finance::Bank::SentinelBenefits::Csv401kConverter::LineParser;
2 $Finance::Bank::SentinelBenefits::Csv401kConverter::LineParser::VERSION = '1.2';
3 use Modern::Perl;
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.2
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 use Moose;
26  
27 use Finance::Bank::SentinelBenefits::Csv401kConverter::SymbolMap;
28 use Finance::Bank::SentinelBenefits::Csv401kConverter::Line;
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 NUMBER_OF_FIELDS => 7,
40 };
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 my $self = shift;
103 my $line = shift;
104 my $date = shift;
105  
106 my @line_parts = split /,/, $line;
107  
108 if(NUMBER_OF_FIELDS() == @line_parts
109 && $line_parts[0] =~ m/Employe. .+ Contribution/){
110
111 my ($contribution_type, $status, $memo, $quantity, $price, $total, $redemption_fee) = @line_parts;
112  
113 $total =~ s/\$//;
114  
115 my $parsed_line = Finance::Bank::SentinelBenefits::Csv401kConverter::Line->new( {
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 return $parsed_line;
129 }
130  
131 return;
132 }
133  
134 no Moose;
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