blib/lib/Lingua/SV/Num2Word.pm

filter: Statementstmt 100% 39 / 39 Branchbran 87.5% 21 / 24 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 95.9% 71 / 74 CC 14 SCAR 24.1
CC
14
Cov
95%
num2sv_cardinal
14.0
BEGIN
1.0
BEGIN
1.0
CRAP 11.1
↑ Summary
1 # For Emacs: -*- mode:cperl; mode:folding coding:iso-8859-1 -*-
2 #
3 # Started by Vitor Serra Mori at 2004-05-19
4 #
5 # PPCG: 0.7
6  
7 package Lingua::SV::Num2Word;
8  
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶ use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶ use vars qw($VERSION @ISA @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 $VERSION = '0.05';
15 1 @ISA = qw(Exporter);
16 1 @EXPORT_OK = qw(&num2sv_cardinal);
17 }
18  
19 # {{{ num2sv_cardinal convert number to text
20 #
21 36 ▶sub num2sv_cardinal {
Subroutine num2sv_cardinal: called CC=14 SCAR=26.4
Pod documented
22 36 ▶ my $positive = ($_[0]>=0) ? shift : return;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] >= 0 ? : 36 0 36
23 36 my $out;
24 36 my @tokens1 = qw(noll ett två tre fyra fem sex sju åtta nio tio elva
25 tolv tretton fjorton femton sexton sjutton arton nitton); # 0-19 Cardinals
26 36 my @tokens2 = qw(tjugo trettio fyrtio femtio sextio sjutio åttio nittio); # 20-90 Cardinals (end with zero)
27  
28 36 ▶ return $tokens1[$positive] if($positive < 20); # interval 0 - 19
Branch: 1 branch
BranchTrueFalseTotal
if $positive < 20 6 30 36
29  
30 30 ▶ if($positive < 100) { # interval 20 - 99
Branch: 4 branches
BranchTrueFalseTotal
if ($positive < 100) { } 3 27 30
elsif ($positive < 1000) { } 14 13 27
elsif ($positive < 1000000) { } 9 4 13
elsif ($positive < 1000000000) { } 3 1 4
31 3 my @num = split '',$positive;
32  
33 3 $out = $tokens2[$num[0]-2];
34 3 ▶ $out .= $tokens1[$num[1]] if ($num[1]);
Branch: 1 branch
BranchTrueFalseTotal
if $num[1] 3 0 3
35 } elsif($positive < 1000) { # interval 100 - 999
36 14 my @num = split '',$positive;
37  
38 14 $out = $tokens1[$num[0]].'hundra';
39  
40 14 ▶ if ((int $num[1].$num[2]) < 20 && (int $num[1].$num[2])>0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (int $num[1] . $num[2] < 20 and int $num[1] . $num[2] > 0) { } 1 13 14
Condition100%3/3
int $num[1] . $num[2] < 20 and int $num[1] . $num[2] > 0
!ll&&!rl&&r
1121
MC/DC100%2/2
int $num[1] . $num[2] < 20 and int $num[1] . $num[2] > 0
int $num[1] . $num[2] < 20 int $num[1] . $num[2] > 0
Truth table100%3/3
A and B
A= int $num[1] . $num[2] < 20B= int $num[1] . $num[2] > 0
ABresult
0X0
100
111
41 1 $out .= &num2sv_cardinal(int $num[1].$num[2]);
42 } else {
43 13 ▶ $out .= $tokens2[$num[1]-2] if($num[1]);
Branch: 1 branch
BranchTrueFalseTotal
if $num[1] 11 2 13
44 13 ▶ $out .= $tokens1[$num[2]] if($num[2]);
Branch: 1 branch
BranchTrueFalseTotal
if $num[2] 11 2 13
45 }
46 } elsif($positive < 1000_000) { # interval 1000 - 999_999
47 9 my @num = split '',$positive;
48 9 my @sub = splice @num,-3;
49  
50 9 $out = &num2sv_cardinal(int join '',@num);
51 9 $out .= 'tusen';
52 9 ▶ $out .= &num2sv_cardinal(int join '',@sub) if (int(join "",@sub) >0);
Branch: 1 branch
BranchTrueFalseTotal
if int join("", @sub) > 0 6 3 9
53 } elsif($positive < 1_000_000_000) { # interval 1_000_000 - 999_999_999
54 3 my @num = split '',$positive;
55 3 my @sub = splice @num,-6;
56  
57 3 $out = &num2sv_cardinal(int join '',@num);
58 3 $out .= ' miljoner ';
59 3 ▶ $out .= &num2sv_cardinal(int join '',@sub) if (int(join "",@sub) >0);
Branch: 1 branch
BranchTrueFalseTotal
if int join("", @sub) > 0 3 0 3
60 }
61  
62 30 return $out;
63 }
64  
65 # }}}
66  
67 1 1;
68 __END__
↑ Summary