blib/lib/Lingua/GLG/Word2Num.pm

filter: Statementstmt 100% 26 / 26 Branchbran n/a Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 100% 39 / 39 CC 2 SCAR 2.0
CC
2
Cov
100%
w2n
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
↑ Summary
1 # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8; -*-
2  
3 package Lingua::GLG::Word2Num;
4 # ABSTRACT: Word to number conversion in Galician
5  
6 1 ▶use 5.16.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # {{{ use block
11  
12 1 ▶use Parse::RecDescent;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Export::Attrs;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # }}}
16 # {{{ var block
17 1 our $VERSION = '0.2603270';
18 1 my $parser = glg_numerals();
19  
20 # }}}
21  
22 # {{{ w2n convert text to number
23  
24 sub w2n :Export {
25 9 ▶ my $input = shift // return;
Subroutine w2n: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
shift() // (return)
l!l
81
MC/DC100%1/1
shift() // (return)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
26  
27 8 $input = lc $input;
28 8 $input =~ s/\s+/ /g;
29 8 $input =~ s/^\s+|\s+$//g;
30  
31 8 return $parser->numeral($input);
32 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
33 # }}}
34 # {{{ glg_numerals create parser for numerals
35  
36 sub glg_numerals {
37 1 ▶ return Parse::RecDescent->new(q{
Subroutine glg_numerals: called CC=1 SCAR=0.0
Pod documented
38 <autoaction: { $item[1] } >
39 <nocheck>
40  
41 numeral: mega
42 | kOhOd
43 | 'cero' { 0 }
44 | { }
45  
46 number: 'un' { 1 }
47 | 'dous' { 2 }
48 | 'tres' { 3 }
49 | 'catro' { 4 }
50 | 'cinco' { 5 }
51 | 'seis' { 6 }
52 | 'sete' { 7 }
53 | 'oito' { 8 }
54 | 'nove' { 9 }
55 | 'dezaseis' { 16 }
56 | 'dezasete' { 17 }
57 | 'dezaoito' { 18 }
58 | 'dezanove' { 19 }
59 | 'dez' { 10 }
60 | 'once' { 11 }
61 | 'doce' { 12 }
62 | 'trece' { 13 }
63 | 'catorce' { 14 }
64 | 'quince' { 15 }
65  
66 tens: 'vinte' { 20 }
67 | 'trinta' { 30 }
68 | 'corenta' { 40 }
69 | 'cincuenta' { 50 }
70 | 'sesenta' { 60 }
71 | 'setenta' { 70 }
72 | 'oitenta' { 80 }
73 | 'noventa' { 90 }
74  
75 hundreds: 'cincocentos' { 500 }
76 | 'setecentos' { 700 }
77 | 'novecentos' { 900 }
78 | 'oitocentos' { 800 }
79 | 'seiscentos' { 600 }
80 | 'catrocentos' { 400 }
81 | 'trescentos' { 300 }
82 | 'douscentos' { 200 }
83 | /cen(to)?/ { 100 }
84  
85 deca: tens 'e' number { $item[1] + $item[3] }
86 | tens
87 | number
88  
89 hecto: hundreds 'e' deca { $item[1] + $item[3] }
90 | hundreds deca { $item[1] + $item[2] }
91 | hundreds
92  
93 hOd: hecto
94 | deca
95  
96 kilo: hOd milnotmeg 'e' hOd { $item[1] * 1000 + $item[4] }
97 | hOd milnotmeg hOd { $item[1] * 1000 + $item[3] }
98 | hOd milnotmeg { $item[1] * 1000 }
99 | milnotmeg 'e' hOd { 1000 + $item[3] }
100 | milnotmeg hOd { 1000 + $item[2] }
101 | milnotmeg { 1000 }
102  
103 milnotmeg: ...!/mill(ón|óns)/ 'mil'
104  
105 kOhOd: kilo
106 | hOd
107  
108 mega: hOd /mill(óns|ón)/ 'e' kOhOd { $item[1] * 1_000_000 + $item[4] }
109 | hOd /mill(óns|ón)/ kOhOd { $item[1] * 1_000_000 + $item[3] }
110 | hOd /mill(óns|ón)/ { $item[1] * 1_000_000 }
111 });
112 }
113  
114 # }}}
115  
116 1 1;
117  
118 __END__
↑ Summary