blib/lib/Lingua/RU/Number.pm

filter: Statementstmt 100% 64 / 64 Branchbran 82.1% 23 / 28 Conditioncond 54.1% 13 / 24 MC/DCmcdc 18.1% 2 / 11 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 79.8% 107 / 134 SCAR 31.9
CC
23
Cov
86%
get_string
19.2
rur_in_words
7.0
BEGIN
1.0
CRAP 24.4
↑ Summary
1 package Lingua::RU::Number;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 require Exporter;
7 1 require AutoLoader;
8  
9 1 @ISA = qw(Exporter AutoLoader);
10 # Items to export into callers namespace by default. Note: do not export
11 # names by default without a very good reason. Use EXPORT_OK instead.
12 # Do not simply export all your public functions/methods/constants.
13 1 @EXPORT = qw();
14 1 @EXPORT_OK = qw(rur_in_words);
15  
16 1 $VERSION = '0.6';
17  
18 # Preloaded methods go here.
19 1 ▶use vars qw(%diw %nom);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 %diw = (
22 0 => {
23 0 => { 0 => "ноль", 1 => 1},
24 1 => { 0 => "", 1 => 2},
25 2 => { 0 => "", 1 => 3},
26 3 => { 0 => "три", 1 => 0},
27 4 => { 0 => "четыре", 1 => 0},
28 5 => { 0 => "пять", 1 => 1},
29 6 => { 0 => "шесть", 1 => 1},
30 7 => { 0 => "семь", 1 => 1},
31 8 => { 0 => "восемь", 1 => 1},
32 9 => { 0 => "девять", 1 => 1},
33 10 => { 0 => "десять", 1 => 1},
34 11 => { 0 => "одиннадцать", 1 => 1},
35 12 => { 0 => "двенадцать", 1 => 1},
36 13 => { 0 => "тринадцать", 1 => 1},
37 14 => { 0 => "четырнадцать", 1 => 1},
38 15 => { 0 => "пятнадцать", 1 => 1},
39 16 => { 0 => "шестнадцать", 1 => 1},
40 17 => { 0 => "семнадцать", 1 => 1},
41 18 => { 0 => "восемнадцать", 1 => 1},
42 19 => { 0 => "девятнадцать", 1 => 1},
43 },
44 1 => {
45 2 => { 0 => "двадцать", 1 => 1},
46 3 => { 0 => "тридцать", 1 => 1},
47 4 => { 0 => "сорок", 1 => 1},
48 5 => { 0 => "пятьдесят", 1 => 1},
49 6 => { 0 => "шестьдесят", 1 => 1},
50 7 => { 0 => "семьдесят", 1 => 1},
51 8 => { 0 => "восемьдесят", 1 => 1},
52 9 => { 0 => "девяносто", 1 => 1},
53 },
54 2 => {
55 1 => { 0 => "сто", 1 => 1},
56 2 => { 0 => "двести", 1 => 1},
57 3 => { 0 => "триста", 1 => 1},
58 4 => { 0 => "четыреста", 1 => 1},
59 5 => { 0 => "пятьсот", 1 => 1},
60 6 => { 0 => "шестьсот", 1 => 1},
61 7 => { 0 => "семьсот", 1 => 1},
62 8 => { 0 => "восемьсот", 1 => 1},
63 9 => { 0 => "девятьсот", 1 => 1}
64 }
65 );
66  
67 1 %nom = (
68 0 => {0 => "копейки", 1 => "копеек", 2 => "одна копейка", 3 => "две копейки"},
69 1 => {0 => "рубля", 1 => "рублей", 2 => "один рубль", 3 => "два рубля"},
70 2 => {0 => "тысячи", 1 => "тысяч", 2 => "одна тысяча", 3 => "две тысячи"},
71 3 => {0 => "миллиона", 1 => "миллионов", 2 => "один миллион", 3 => "два миллиона"},
72 4 => {0 => "миллиарда",1 => "миллиардов",2 => "один миллиард",3 => "два миллиарда"},
73 5 => {0 => "триллиона",1 => "триллионов",2 => "один триллион",3 => "два триллиона"}
74 );
75  
76 1 my $out_rub;
77  
78 sub rur_in_words
79 {
80 5 ▶ my ($sum) = shift;
Subroutine rur_in_words: called CC=7 SCAR=19.5
Pod undocumented
81 5 my ($retval, $i, $sum_rub, $sum_kop);
82  
83 5 $retval = "";
84 5 ▶ $out_rub = ($sum >= 1) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$sum >= 1 ? : 5 0 5
85 5 $sum_rub = sprintf("%0.0f", $sum);
86 5 ▶ $sum_rub-- if (($sum_rub - $sum) > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $sum_rub - $sum > 0 3 2 5
87 5 $sum_kop = sprintf("%0.2f",($sum - $sum_rub))*100;
88  
89 5 my $kop = get_string($sum_kop, 0);
90  
91 5 ▶ for ($i=1; $i<6 && $sum_rub >= 1; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 6 and $sum_rub >= 1) 6 5 11
Condition66%2/3
$i < 6 and $sum_rub >= 1
!ll&&!rl&&r
056
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
92 6 my $sum_tmp = $sum_rub/1000;
93 6 my $sum_part = sprintf("%0.3f", $sum_tmp - int($sum_tmp))*1000;
94 6 $sum_rub = sprintf("%0.0f",$sum_tmp);
95  
96 6 ▶ $sum_rub-- if ($sum_rub - $sum_tmp > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $sum_rub - $sum_tmp > 0 1 5 6
97 6 $retval = get_string($sum_part, $i)." ".$retval;
98 }
99 5 ▶ $retval .= " рублей" if ($out_rub == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $out_rub == 0 0 5 5
100 5 $retval .= " ".$kop;
101 5 $retval =~ s/\s+/ /g;
102 5 return $retval;
103 }
104  
105 sub get_string
106 {
107 11 ▶ my ($sum, $nominal) = @_;
Subroutine get_string: called CC=17 SCAR=29.6
Pod undocumented
108 11 my ($retval, $nom) = ('', -1);
109  
110 11 ▶ if (($nominal == 0 && $sum < 100) || ($nominal > 0 && $nominal < 6 && $sum < 1000)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nominal == 0 and $sum < 100 or $nominal > 0 and $nominal < 6 and $sum < 1000) 11 0 11
Condition50%6/12
$nominal == 0 and $sum < 100 or $nominal > 0 and $nominal < 6 and $sum < 1000
l!l&&r!l&&!r
560
$nominal == 0 and $sum < 100
!ll&&!rl&&r
605
$nominal > 0 and $nominal < 6 and $sum < 1000
!ll&&!rl&&r
006
$nominal > 0 and $nominal < 6
!ll&&!rl&&r
006
MC/DC0%0/5
$nominal == 0 and $sum < 100 or $nominal > 0 and $nominal < 6 and $sum < 1000
$nominal == 0 $sum < 100 $nominal > 0 $nominal < 6 $sum < 1000
Truth table22%2/9
A and B or C and D and E
A= $nominal == 0B= $sum < 100C= $nominal > 0D= $nominal < 6E= $sum < 1000
ABCDEresult
11XXX1
0X1111
101111
0X0XX0
0X10X0
0X1100
100XX0
1010X0
101100
111 11 my $s2 = int($sum/100);
112 11 ▶ if ($s2 > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s2 > 0) 1 10 11
113 1 $retval .= " ".$diw{2}{$s2}{0};
114 1 $nom = $diw{2}{$s2}{1};
115 }
116 11 my $sx = sprintf("%0.0f", $sum - $s2*100);
117 11 ▶ $sx-- if ($sx - ($sum - $s2*100) > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $sx - ($sum - $s2 * 100) > 0 3 8 11
118  
119 11 ▶ if (($sx<20 && $sx>0) || ($sx == 0 && $nominal == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sx < 20 and $sx > 0 or $sx == 0 and $nominal == 0) { } 5 6 11
Condition55%5/9
$sx < 20 and $sx > 0 or $sx == 0 and $nominal == 0
l!l&&r!l&&!r
506
$sx < 20 and $sx > 0
!ll&&!rl&&r
605
$sx == 0 and $nominal == 0
!ll&&!rl&&r
600
MC/DC25%1/4
$sx < 20 and $sx > 0 or $sx == 0 and $nominal == 0
$sx < 20 $sx > 0 $sx == 0 $nominal == 0
Truth table28%2/7
A and B or C and D
A= $sx < 20B= $sx > 0C= $sx == 0D= $nominal == 0
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
120 5 $retval .= " ".$diw{0}{$sx}{0};
121 5 $nom = $diw{0}{$sx}{1};
122 } else {
123 6 my $s1 = sprintf("%0.0f",$sx/10);
124 6 ▶ $s1-- if (($s1 - $sx/10) > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $s1 - $sx / 10 > 0 5 1 6
125 6 my $s0 = int($sum - $s2*100 - $s1*10 + 0.5);
126 6 ▶ if ($s1 > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s1 > 0) 6 0 6
127 6 $retval .= " ".$diw{1}{$s1}{0};
128 6 $nom = $diw{1}{$s1}{1};
129 }
130 6 ▶ if ($s0 > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s0 > 0) 5 1 6
131 5 $retval .= " ".$diw{0}{$s0}{0};
132 5 $nom = $diw{0}{$s0}{1};
133 }
134 }
135 }
136 11 ▶ if ($nom >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nom >= 0) 11 0 11
137 11 $retval .= " ".$nom{$nominal}{$nom};
138 11 ▶ $out_rub = 1 if ($nominal == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $nominal == 1 5 6 11
139 }
140 11 $retval =~ s/^\s*//g;
141 11 $retval =~ s/\s*$//g;
142  
143 11 return $retval;
144 }
145  
146 # Autoload methods go after =cut, and are processed by the autosplit program.
147  
148 1 1;
149 __END__
↑ Summary