blib/lib/Lingua/RUS/Number.pm

filter: Statementstmt 100% 71 / 71 Branchbran 73.3% 22 / 30 Conditioncond 74.1% 23 / 31 MC/DCmcdc 40.0% 6 / 15 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 84.1% 133 / 158 CC 27 SCAR 26.7
CC
27
Cov
88%
get_string
21.7
rur_in_words
8.1
BEGIN
1.0
CRAP 14.5
↑ Summary
1 # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8 -*-
2 #
3 # (c) 2002-2010 PetaMem, s.r.o.
4 #
5  
6 package Lingua::RUS::Number;
7 # ABSTRACT: Number 2 word conversion in RUS.
8  
9 1 ▶use 5.16.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # {{{ use block
14  
15 1 ▶use Export::Attrs;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # }}}
18 # {{{ variables declaration
19 1 our $VERSION = '0.2603260';
20  
21 # Preloaded methods go here.
22 1 ▶use vars qw(%diw %nom);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 %diw = (
25 0 => {
26 0 => { 0 => "ноль", 1 => 1},
27 1 => { 0 => "", 1 => 2},
28 2 => { 0 => "", 1 => 3},
29 3 => { 0 => "три", 1 => 0},
30 4 => { 0 => "четыре", 1 => 0},
31 5 => { 0 => "пять", 1 => 1},
32 6 => { 0 => "шесть", 1 => 1},
33 7 => { 0 => "семь", 1 => 1},
34 8 => { 0 => "восемь", 1 => 1},
35 9 => { 0 => "девять", 1 => 1},
36 10 => { 0 => "десять", 1 => 1},
37 11 => { 0 => "одинадцать", 1 => 1},
38 12 => { 0 => "двенадцать", 1 => 1},
39 13 => { 0 => "тринадцать", 1 => 1},
40 14 => { 0 => "четырнадцать", 1 => 1},
41 15 => { 0 => "пятнадцать", 1 => 1},
42 16 => { 0 => "шестнадцать", 1 => 1},
43 17 => { 0 => "семнадцать", 1 => 1},
44 18 => { 0 => "восемнадцать", 1 => 1},
45 19 => { 0 => "девятнадцать", 1 => 1},
46 },
47 1 => {
48 2 => { 0 => "двадцать", 1 => 1},
49 3 => { 0 => "тридцать", 1 => 1},
50 4 => { 0 => "сорок", 1 => 1},
51 5 => { 0 => "пятьдесят", 1 => 1},
52 6 => { 0 => "шестьдесят", 1 => 1},
53 7 => { 0 => "семьдесят", 1 => 1},
54 8 => { 0 => "восемьдесят", 1 => 1},
55 9 => { 0 => "девяносто", 1 => 1},
56 },
57 2 => {
58 1 => { 0 => "сто", 1 => 1},
59 2 => { 0 => "двести", 1 => 1},
60 3 => { 0 => "триста", 1 => 1},
61 4 => { 0 => "четыреста", 1 => 1},
62 5 => { 0 => "пятьсот", 1 => 1},
63 6 => { 0 => "шестьсот", 1 => 1},
64 7 => { 0 => "семьсот", 1 => 1},
65 8 => { 0 => "восемьсот", 1 => 1},
66 9 => { 0 => "девятьсот", 1 => 1}
67 }
68 );
69  
70 1 %nom = (
71 0 => {0 => "копейки", 1 => "копеек", 2 => "одна копейка", 3 => "две копейки"},
72 1 => {0 => "рубля", 1 => "рублей", 2 => "один рубль", 3 => "два рубля"},
73 2 => {0 => "тысячи", 1 => "тысяч", 2 => "одна тысяча", 3 => "две тысячи"},
74 3 => {0 => "миллиона", 1 => "миллионов", 2 => "один миллион", 3 => "два миллиона"},
75 4 => {0 => "миллиарда",1 => "миллиардов",2 => "один миллиард",3 => "два миллиарда"},
76 5 => {0 => "триллиона",1 => "триллионов",2 => "один триллион",3 => "два триллиона"}
77 );
78  
79 1 my $out_rub;
80  
81 # }}}
82  
83 # {{{ rur_in_words
84  
85 sub rur_in_words :Export {
86 6 ▶ my ($sum) = shift // 0;
Subroutine rur_in_words: called CC=8 SCAR=20.9
Pod documented
Condition100%2/2
shift() // 0
l!l
51
MC/DC100%1/1
shift() // 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
87 6 my ($retval, $i, $sum_rub, $sum_kop);
88  
89 6 $retval = "";
90 6 ▶ $out_rub = ($sum >= 1) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$sum >= 1 ? : 3 3 6
91 6 $sum_rub = sprintf("%d", $sum);
92 6 ▶ $sum_rub-- if (($sum_rub - $sum) > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $sum_rub - $sum > 0 0 6 6
93 6 $sum_kop = sprintf("%0.2f", ($sum - $sum_rub)) * 100;
94 6 my $kop = get_string($sum_kop, 0);
95  
96 6 ▶ for ($i=1; $i<6 && $sum_rub >= 1; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 6 and $sum_rub >= 1) 4 6 10
Condition66%2/3
$i < 6 and $sum_rub >= 1
!ll&&!rl&&r
064
MC/DC50%1/2
$i < 6 and $sum_rub >= 1
$i < 6 $sum_rub >= 1
Truth table66%2/3
A and B
A= $i < 6B= $sum_rub >= 1
ABresult
0X0
100
111
97 4 my $sum_tmp = $sum_rub / 1000;
98 4 my $sum_part = sprintf("%0.3f", $sum_tmp - sprintf("%d", $sum_tmp) ) * 1000;
99 4 $sum_rub = sprintf("%d", $sum_tmp);
100  
101 4 ▶ $sum_rub-- if ($sum_rub - $sum_tmp > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $sum_rub - $sum_tmp > 0 0 4 4
102 4 $retval = get_string($sum_part, $i)." ".$retval;
103 }
104 6 ▶ $retval .= " рублей" if ($out_rub == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $out_rub == 0 0 6 6
105 6 $retval .= " ".$kop;
106 6 $retval =~ s/\s+/ /g;
107  
108 6 return $retval;
109 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
110  
111 # }}}
112 # {{{ get_string
113  
114 sub get_string :Export{
115 17 ▶ my $sum = shift // return;
Subroutine get_string: called CC=20 SCAR=30.8
Pod documented
Condition100%2/2
shift() // (return)
l!l
152
MC/DC100%1/1
shift() // (return)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
116 15 my $nominal = shift;
117 15 my ($retval, $nom) = ('', -1);
118  
119 15 ▶ if ((!$nominal && $sum < 100) || ($nominal > 0 && $nominal < 6 && $sum < 1000)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $nominal and $sum < 100 or $nominal > 0 and $nominal < 6 and $sum < 1000) 15 0 15
Condition50%6/12
not $nominal and $sum < 100 or $nominal > 0 and $nominal < 6 and $sum < 1000
l!l&&r!l&&!r
870
not $nominal and $sum < 100
!ll&&!rl&&r
708
$nominal > 0 and $nominal < 6 and $sum < 1000
!ll&&!rl&&r
007
$nominal > 0 and $nominal < 6
!ll&&!rl&&r
007
MC/DC0%0/5
not $nominal and $sum < 100 or $nominal > 0 and $nominal < 6 and $sum < 1000
not $nominal $sum < 100 $nominal > 0 $nominal < 6 $sum < 1000
Truth table22%2/9
not(A) and B or C and D and E
A= not $nominalB= $sum < 100C= $nominal > 0D= $nominal < 6E= $sum < 1000
ABCDEresult
11XXX1
0X1111
101111
0X0XX0
0X10X0
0X1100
100XX0
1010X0
101100
120 15 my $s2 = sprintf("%d", $sum / 100);
121 15 ▶ if ($s2 > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s2 > 0) 2 13 15
122 2 $retval .= ' '.$diw{2}{$s2}{0};
123 2 $nom = $diw{2}{$s2}{1};
124 }
125 15 my $sx = sprintf("%d", $sum - $s2 * 100);
126 15 ▶ $sx-- if ($sx - ($sum - $s2*100) > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $sx - ($sum - $s2 * 100) > 0 0 15 15
127  
128 15 ▶ if (($sx<20 && $sx>0) || ($sx == 0 && !$nominal)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sx < 20 and $sx > 0 or $sx == 0 and not $nominal) { } 12 3 15
Condition88%8/9
$sx < 20 and $sx > 0 or $sx == 0 and not $nominal
l!l&&r!l&&!r
663
$sx < 20 and $sx > 0
!ll&&!rl&&r
366
$sx == 0 and not $nominal
!ll&&!rl&&r
306
MC/DC25%1/4
$sx < 20 and $sx > 0 or $sx == 0 and not $nominal
$sx < 20 $sx > 0 $sx == 0 not $nominal
Truth table42%3/7
A and B or C and not(D)
A= $sx < 20B= $sx > 0C= $sx == 0D= not $nominal
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
129 12 $retval .= " ".$diw{0}{$sx}{0};
130 12 $nom = $diw{0}{$sx}{1};
131 } else {
132 3 my $s1 = sprintf("%d", $sx / 10);
133 3 ▶ $s1-- if (($s1 - $sx/10) > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $s1 - $sx / 10 > 0 0 3 3
134 3 my $s0 = sprintf("%d", $sum - $s2*100 - $s1*10 + 0.5);
135 3 ▶ if ($s1 > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s1 > 0) 3 0 3
136 3 $retval .= ' '.$diw{1}{$s1}{0};
137 3 $nom = $diw{1}{$s1}{1};
138 }
139 3 ▶ if ($s0 > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s0 > 0) 2 1 3
140 2 $retval .= ' '.$diw{0}{$s0}{0};
141 2 $nom = $diw{0}{$s0}{1};
142 }
143 }
144 }
145 15 ▶ if ($nom >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nom >= 0) 15 0 15
146 15 ▶ $retval .= defined $nominal ? ' '.$nom{$nominal}{$nom} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $nominal ? : 14 1 15
147 15 ▶ $out_rub = 1 if (defined $nominal && $nominal == 1);
Branch: 1 branch
BranchTrueFalseTotal
if defined $nominal and $nominal == 1 4 11 15
Condition100%3/3
defined $nominal and $nominal == 1
!ll&&!rl&&r
1104
MC/DC100%2/2
defined $nominal and $nominal == 1
defined $nominal $nominal == 1
Truth table100%3/3
A and B
A= defined $nominalB= $nominal == 1
ABresult
0X0
100
111
148 }
149 15 $retval =~ s/^\s*//g;
150 15 $retval =~ s/\s*$//g;
151  
152 15 return $retval;
153 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
154  
155 # }}}
156  
157 1 1;
158  
159 __END__
↑ Summary