File Coverage

blib/lib/Lingua/FRA/Word2Num.pm
Criterion Covered Total %
statement 14 14 100.0
branch n/a
condition 2 2 100.0
subroutine 6 6 100.0
pod 2 2 100.0
total 24 24 100.0


line stmt bran cond sub pod time code
1             # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8; -*-
2              
3             package Lingua::FRA::Word2Num;
4             # ABSTRACT: Word 2 number conversion in FRA.
5              
6             # {{{ use block
7              
8 1     1   105939 use 5.16.0;
  1         3  
9 1     1   4 use utf8;
  1         2  
  1         11  
10              
11 1     1   28 use base qw(Exporter);
  1         1  
  1         131  
12              
13 1     1   1141 use Parse::RecDescent;
  1         61054  
  1         11  
14              
15             # }}}
16             # {{{ var block
17             our $VERSION = '0.2603230';
18             our @EXPORT_OK = qw(cardinal2num w2n);
19             my $parser = fra_numerals();
20              
21             # }}}
22              
23             # {{{ w2n convert number to text
24              
25             sub w2n {
26 4   100 4 1 345293 my $input = shift // return;
27              
28              
29 3         41 return $parser->numeral($input);
30             }
31              
32             # }}}
33             # {{{ fra_numerals create parser for numerals
34              
35             sub fra_numerals {
36 1     1 1 6 return Parse::RecDescent->new(q{
37            
38              
39             numeral: mega
40             | kOhOd
41             | 'zéro' { 0 }
42             | { }
43              
44             number: 'un' { 1 }
45             | 'deux' { 2 }
46             | 'trois' { 3 }
47             | 'quatre' { 4 }
48             | 'cinq' { 5 }
49             | 'six' { 6 }
50             | 'sept' { 7 }
51             | 'huit' { 8 }
52             | 'neuf' { 9 }
53             | 'dix-sept' { 17 }
54             | 'dix-huit' { 18 }
55             | 'dix-neuf' { 19 }
56             | 'dix' { 10 }
57             | 'onze' { 11 }
58             | 'douze' { 12 }
59             | 'treize' { 13 }
60             | 'quatorze' { 14 }
61             | 'quinze' { 15 }
62             | 'seize' { 16 }
63              
64             tens: 'vingt' { 20 }
65             | 'trente' { 30 }
66             | 'quarante' { 40 }
67             | 'cinquante' { 50 }
68             | 'soixante-dix' { 70 }
69             | 'soixante' { 60 }
70             | /quatre-vingts?/ { 80 }
71              
72             deca: tens /-?/ number { $item[1] + $item[3] }
73             | tens 'et' number { $item[1] + $item[3] }
74             | tens
75             | number
76              
77             hecto: number /cents?/ deca { $item[1] * 100 + $item[3] }
78             | number /cents?/ { $item[1] * 100 }
79             | /cents?/ deca { 100 + $item[2] }
80             | 'cent' { 100 }
81              
82             hOd: hecto
83             | deca
84              
85             kilo: hOd /milles?/ hOd { $item[1] * 1000 + $item[3] }
86             | hOd /milles?/ { $item[1] * 1000 }
87             | /milles?/ hOd { 1000 + $item[2] }
88             | 'mille' { 1000 }
89              
90             kOhOd: kilo
91             | hOd
92              
93             mega: kOhOd /millions?/ kOhOd { $item[1] * 1_000_000 + $item[3] }
94             });
95             }
96             # }}}
97              
98             1;
99              
100             __END__