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

filter: Statementstmt 100% 31 / 31 Branchbran 100% 10 / 10 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 100% 54 / 54 CC 7 SCAR 14.4
CC
7
Cov
100%
parse_line
7.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.2
↑ Summary lib/Finance/Bank/SentinelBenefits/Csv401kConverter.pm »
1 package Finance::Bank::SentinelBenefits::Csv401kConverter::LineParser;
2 6 $Finance::Bank::SentinelBenefits::Csv401kConverter::LineParser::VERSION = '1.3';
3 6 ▶use Modern::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 6 ▶use Finance::Bank::SentinelBenefits::Csv401kConverter::SymbolMap;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 6 ▶use Finance::Bank::SentinelBenefits::Csv401kConverter::Line;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30  
31 =head1 CONSTANTS
32  
33 =head2 NUMBER_OF_FIELDS
34  
35 Number of fields in the Sentinel file
36  
37 =cut
38 6 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
39 6 NUMBER_OF_FIELDS => 7,
40 6 };
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 6 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 66 ▶sub parse_line {
Subroutine parse_line: called CC=7 SCAR=19.5
Pod documented
102 66 my $self = shift;
103 66 my $line = shift;
104 66 my $date = shift;
105  
106 66 my @line_parts = split /,/, $line;
107  
108 66 ▶ if(NUMBER_OF_FIELDS() == @line_parts
Branch: 1 branch
BranchTrueFalseTotal
if (7 == @line_parts and $line_parts[0] =~ /Employe. .+ Contribution/u) 34 32 66
Condition100%3/3
7 == @line_parts and $line_parts[0] =~ /Employe. .+ Contribution/u
!ll&&!rl&&r
221034
MC/DC100%2/2
7 == @line_parts and $line_parts[0] =~ /Employe. .+ Contribution/u
7 == @line_parts $line_parts[0] =~ /Employe. .+ Contribution/u
Truth table100%3/3
A and B
A= 7 == @line_partsB= $line_parts[0] =~ /Employe. .+ Contribution/u
ABresult
0X0
100
111
109 && $line_parts[0] =~ m/Employe. .+ Contribution/){
110
111 34 my ($contribution_type, $status, $memo, $quantity, $price, $total, $redemption_fee) = @line_parts;
112  
113 34 $total =~ s/\$//;
114  
115 34 ▶ my $parsed_line = Finance::Bank::SentinelBenefits::Csv401kConverter::Line->new( {
Branch: 4 branches
BranchTrueFalseTotal
$memo =~ /^Sell/u ? : 4 30 34
$memo =~ m[^Gain/Loss]u ? : 4 26 30
$memo =~ /^Dividend/u ? : 4 22 26
$contribution_type =~ /Employer Matching Contribution/u ? : 20 14 34
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 return $parsed_line;
129 }
130  
131 32 return;
132 }
133  
134 6 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
135  
136 6 __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
↑ Summary lib/Finance/Bank/SentinelBenefits/Csv401kConverter.pm »