| 1 | package Lingua::PT::Nums2Ords; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 3 | ▶ | use Lingua::PT::Nums2Words qw/num2word/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 3 | require Exporter; | |||||||||
| 10 | |||||||||||
| 11 | 3 | our @ISA = qw(Exporter); | |||||||||
| 12 | |||||||||||
| 13 | 3 | our %EXPORT_TAGS = ( 'all' => [ qw( | |||||||||
| 14 | num2ord | ||||||||||
| 15 | ) ] ); | ||||||||||
| 16 | |||||||||||
| 17 | 3 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||
| 18 | |||||||||||
| 19 | 3 | our @EXPORT = qw( | |||||||||
| 20 | ); | ||||||||||
| 21 | |||||||||||
| 22 | 3 | our $VERSION = '0.08'; | |||||||||
| 23 | |||||||||||
| 24 | =head1 NAME | ||||||||||
| 25 | |||||||||||
| 26 | Lingua::PT::Nums2Ords - Converts numbers to Portuguese ordinals | ||||||||||
| 27 | |||||||||||
| 28 | =head1 SYNOPSIS | ||||||||||
| 29 | |||||||||||
| 30 | use Lingua::PT::Nums2Ords qw/num2ord/; | ||||||||||
| 31 | |||||||||||
| 32 | $ord = num2ord(20) # "vigesimo" | ||||||||||
| 33 | |||||||||||
| 34 | @ord = num2ord(1,2,3) # qw(primeiro segundo terceiro) | ||||||||||
| 35 | |||||||||||
| 36 | =head1 DESCRIPTION | ||||||||||
| 37 | |||||||||||
| 38 | Converts numbers to Portuguese ordinals. Works up to 999.999.999.999 | ||||||||||
| 39 | ('novecentos e noventa e nove bilionesimos novecentos e noventa e | ||||||||||
| 40 | nove milionesimos novecentos e noventa e nove milesimos nongentesimo | ||||||||||
| 41 | nonagesimo nono'). | ||||||||||
| 42 | |||||||||||
| 43 | =head2 num2ord | ||||||||||
| 44 | |||||||||||
| 45 | This is the only function in the module. It turns a number into an | ||||||||||
| 46 | ordinal. | ||||||||||
| 47 | |||||||||||
| 48 | $ord = num2ord(2) | ||||||||||
| 49 | # $ord now holds "segundo" | ||||||||||
| 50 | |||||||||||
| 51 | =cut | ||||||||||
| 52 | |||||||||||
| 53 | 51 | ▶ | sub num2ord { | ||||||||
|
Subroutine
num2ord: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||
| 54 | 51 | ▶ | @_ || return (); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 50 | ▶ | my @numbers = wantarray ? @_ : shift; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | my @results = map { | ||||||||||
| 57 | 50 | ▶ | $_ < 0 && return $_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 52 | ▶ | $_ > 999999999999 && return $_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | |||||||||||
| 60 | 52 | s/(?<!\d)1(?=\d{9}$)/bilionésimo /; | |||||||||
| 61 | 52 | s/(\d{1,3})(?=\d{9})/num2word($1).' bilionésimos '/e; | |||||||||
| 62 | |||||||||||
| 63 | 52 | s/(?<!\d)0+//; | |||||||||
| 64 | |||||||||||
| 65 | 52 | s/(?<!\d)1(?=\d{6}$)/milionésimo /; | |||||||||
| 66 | 52 | s/(\d{1,3})(?=\d{6})/num2word($1).' milionésimos '/e; | |||||||||
| 67 | |||||||||||
| 68 | 52 | s/(?<!\d)0+//; | |||||||||
| 69 | |||||||||||
| 70 | 52 | s/(?<!\d)1(?=\d{3}$)/milésimo /; | |||||||||
| 71 | 52 | s/(\d{1,3})(?=\d{3})/num2word($1).' milésimos '/e; | |||||||||
| 72 | |||||||||||
| 73 | 52 | s/(?<!\d)0//; | |||||||||
| 74 | |||||||||||
| 75 | 52 | s/9(?=\d\d)/nongentésimo /; | |||||||||
| 76 | 52 | s/8(?=\d\d)/octigentésimo /; | |||||||||
| 77 | 52 | s/7(?=\d\d)/septigentésimo /; | |||||||||
| 78 | 52 | s/6(?=\d\d)/seiscentésimo /; | |||||||||
| 79 | 52 | s/5(?=\d\d)/quingentésimo /; | |||||||||
| 80 | 52 | s/4(?=\d\d)/quadrigentésimo /; | |||||||||
| 81 | 52 | s/3(?=\d\d)/tricentésimo /; | |||||||||
| 82 | 52 | s/2(?=\d\d)/ducentésimo /; | |||||||||
| 83 | 52 | s/1(?=\d\d)/centésimo /; | |||||||||
| 84 | |||||||||||
| 85 | 52 | s/(?<!\d)0//; | |||||||||
| 86 | |||||||||||
| 87 | 52 | s/9(?=\d)/nonagésimo /; | |||||||||
| 88 | 52 | s/8(?=\d)/octogésimo /; | |||||||||
| 89 | 52 | s/7(?=\d)/septuagésimo /; | |||||||||
| 90 | 52 | s/6(?=\d)/sexagésimo /; | |||||||||
| 91 | 52 | s/5(?=\d)/quinquagésimo /; | |||||||||
| 92 | 52 | s/4(?=\d)/quadragésimo /; | |||||||||
| 93 | 52 | s/3(?=\d)/trigésimo /; | |||||||||
| 94 | 52 | s/2(?=\d)/vigésimo /; | |||||||||
| 95 | 52 | s/1(?=\d)/décimo /; | |||||||||
| 96 | |||||||||||
| 97 | 52 | s/(?<!\d)0//; | |||||||||
| 98 | |||||||||||
| 99 | 52 | s/9/nono/; | |||||||||
| 100 | 52 | s/8/oitavo/; | |||||||||
| 101 | 52 | s/7/sétimo/; | |||||||||
| 102 | 52 | s/6/sexto/; | |||||||||
| 103 | 52 | s/5/quinto/; | |||||||||
| 104 | 52 | s/4/quarto/; | |||||||||
| 105 | 52 | s/3/terceiro/; | |||||||||
| 106 | 52 | s/2/segundo/; | |||||||||
| 107 | 52 | s/1/primeiro/; | |||||||||
| 108 | |||||||||||
| 109 | 52 | s/ +$//; | |||||||||
| 110 | |||||||||||
| 111 | 52 | $_; | |||||||||
| 112 | } @numbers; | ||||||||||
| 113 | |||||||||||
| 114 | 50 | ▶ | return wantarray ? @numbers : $numbers[0]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | 3 | 1; | |||||||||
| 118 | __END__ | ||||||||||