blib/lib/Lingua/SPA/Word2Num.pm

filter: Statementstmt 100% 23 / 23 Branchbran n/a Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 100% 36 / 36 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::SPA::Word2Num;
4 # ABSTRACT: Word to number conversion in Spanish
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 = spa_numerals();
19  
20 # }}}
21  
22 # {{{ w2n convert text to number
23  
24 sub w2n :Export {
25 4 ▶ my $input = shift // return;
Subroutine w2n: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
shift() // (return)
l!l
31
MC/DC100%1/1
shift() // (return)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
26  
27 3 return $parser->numeral($input);
28 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
29 # }}}
30 # {{{ spa_numerals create parser for numerals
31  
32 sub spa_numerals {
33 1 ▶ return Parse::RecDescent->new(q{
Subroutine spa_numerals: called CC=1 SCAR=0.0
Pod documented
34 <autoaction: { $item[1] } >
35 <nocheck>
36  
37 numeral: mega
38 | kOhOd
39 | 'cero' { 0 }
40 | { }
41  
42 number: 'un' { 1 }
43 | 'dos' { 2 }
44 | 'tres' { 3 }
45 | 'cuatro' { 4 }
46 | 'cinco' { 5 }
47 | 'seis' { 6 }
48 | 'siete' { 7 }
49 | 'ocho' { 8 }
50 | 'nueve' { 9 }
51 | 'diez' { 10 }
52 | 'once' { 11 }
53 | 'doce' { 12 }
54 | 'trece' { 13 }
55 | 'catorce' { 14 }
56 | 'quince' { 15 }
57 | 'dieciséis' { 16 }
58 | 'diecisiete' { 17 }
59 | 'dieciocho' { 18 }
60 | 'diecinueve' { 19 }
61 | 'veinte' { 20 }
62 | 'veintiun' { 21 }
63 | 'veintidós' { 22 }
64 | 'veintitrés' { 23 }
65 | 'veinticuatro' { 24 }
66 | 'veinticinco' { 25 }
67 | 'veintiséis' { 26 }
68 | 'veintisiete' { 27 }
69 | 'veintiocho' { 28 }
70 | 'veintinueve' { 29 }
71  
72 tens: 'treinta' { 30 }
73 | 'cuarenta' { 40 }
74 | 'cincuenta' { 50 }
75 | 'sesenta' { 60 }
76 | 'setenta' { 70 }
77 | 'ochenta' { 80 }
78 | 'noventa' { 90 }
79  
80 hundreds: 'quinientos' { 500 }
81 | 'setecientos' { 700 }
82 | 'novecientos' { 900 }
83 | number /cientos?/ { $item[1] * 100 }
84 | /cien(to)?/ { 100 }
85  
86 deca: tens 'y' number { $item[1] + $item[3] }
87 | tens
88 | number
89  
90 hecto: hundreds deca { $item[1] + $item[2] }
91 | hundreds
92  
93 hOd: hecto
94 | deca
95  
96 kilo: hOd milnotmeg hOd { $item[1] * 1000 + $item[3] }
97 | hOd milnotmeg { $item[1] * 1000 }
98 | milnotmeg hOd { 1000 + $item[2] }
99 | milnotmeg { 1000 }
100  
101 milnotmeg: ...!'mill' 'mil'
102  
103 kOhOd: kilo
104 | hOd
105  
106 mega: hOd /mill(ones|ón)/ kOhOd { $item[1] * 1_000_000 + $item[3] }
107 | hOd /mill(ones|ón)/ { $item[1] * 1_000_000 }
108 });
109 }
110  
111 # }}}
112  
113 1 1;
114  
115 __END__
↑ Summary