| 1 | # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8; -*- | ||
| 2 | # | ||
| 3 | # Jose Luis Rey Barreira (c) 2001-2009 | ||
| 4 | # Copyright (c) PetaMem, s.r.o. 2010-present | ||
| 5 | # | ||
| 6 | |||
| 7 | package Lingua::SPA::Num2Word; | ||
| 8 | # ABSTRACT: Number 2 word conversion in SPA. | ||
| 9 | |||
| 10 | use 5.16.0; | ||
| 11 | use utf8; | ||
| 12 | use warnings; | ||
| 13 | |||
| 14 | # {{{ use block | ||
| 15 | |||
| 16 | use Carp; | ||
| 17 | use Export::Attrs; | ||
| 18 | |||
| 19 | # }}} | ||
| 20 | # {{{ var block | ||
| 21 | our $VERSION = '0.2603270'; | ||
| 22 | |||
| 23 | our @EXPORT_OK = qw( $MALE $FEMALE $NEUTRAL $MALE $FEMALE $NEUTRAL); | ||
| 24 | |||
| 25 | no warnings; ## no critic | ||
| 26 | our $MALE => 'o'; | ||
| 27 | our $FEMALE => 'a'; | ||
| 28 | our $NEUTRAL => ''; | ||
| 29 | use warnings; | ||
| 30 | |||
| 31 | use fields qw/ ACENTOS MAYUSCULAS UNMIL HTML DECIMAL SEPARADORES GENERO | ||
| 32 | POSITIVO NEGATIVO FORMATO /; | ||
| 33 | |||
| 34 | my %opt_alias = qw( | ||
| 35 | ACCENTS ACENTOS | ||
| 36 | UPPERCASE MAYUSCULAS | ||
| 37 | SEPARATORS SEPARADORES | ||
| 38 | GENDER GENERO | ||
| 39 | POSITIVE POSITIVO | ||
| 40 | NEGATIVE NEGATIVO | ||
| 41 | FORMAT FORMATO ); | ||
| 42 | |||
| 43 | my %new_defaults = ( | ||
| 44 | ACENTOS => 1, | ||
| 45 | MAYUSCULAS => 0, | ||
| 46 | UNMIL => 1, | ||
| 47 | HTML => 0, | ||
| 48 | DECIMAL => '.', | ||
| 49 | SEPARADORES => '_', | ||
| 50 | GENERO => $MALE, | ||
| 51 | POSITIVO => '', | ||
| 52 | NEGATIVO => 'menos', | ||
| 53 | FORMATO => 'con %02d ctms.', | ||
| 54 | ); | ||
| 55 | |||
| 56 | # }}} | ||
| 57 | # {{{ new | ||
| 58 | |||
| 59 | sub new { | ||
| 60 | my $self = shift; | ||
| 61 | unless ( ref $self ) { | ||
| 62 | $self = fields::new($self); | ||
| 63 | } | ||
| 64 | |||
| 65 | #%$self = (%new_defaults, @_); | ||
| 66 | { # Compatibility conversion of SEXO into GENERO | ||
| 67 | my %opts = ( %new_defaults, @_ ); | ||
| 68 | if ( $opts{'SEXO'} ) { | ||
| 69 | $opts{'GENERO'} = $opts{'SEXO'}; | ||
| 70 | delete $opts{'SEXO'}; | ||
| 71 | } | ||
| 72 | %$self = %opts | ||
| 73 | } | ||
| 74 | return $self; | ||
| 75 | } | ||
| 76 | |||
| 77 | # }}} | ||
| 78 | # {{{ cardinal | ||
| 79 | |||
| 80 | sub cardinal { | ||
| 81 | my $self = shift; | ||
| 82 | my $num = shift; | ||
| 83 | my ( $sgn, $ent, $frc, $exp ) = parse_num( $num, $self->{'DECIMAL'}, $self->{'SEPARADORES'} ); | ||
| 84 | my @words = cardinal_simple( $ent, $exp, $self->{'UNMIL'}, $self->{'GENERO'} ); | ||
| 85 | if (@words) { | ||
| 86 | unshift @words, $self->{'NEGATIVO'} if $sgn < 0 and $self->{'NEGATIVO'}; | ||
| 87 | unshift @words, $self->{'POSITIVO'} if $sgn > 0 and $self->{'POSITIVO'}; | ||
| 88 | return $self->retval( join( " ", @words ) ); | ||
| 89 | } | ||
| 90 | else { | ||
| 91 | return $self->retval('cero'); | ||
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | # }}} | ||
| 96 | # {{{ real | ||
| 97 | |||
| 98 | sub real { | ||
| 99 | my $self = shift; | ||
| 100 | my ( $num, $genf, $genm ) = @_; | ||
| 101 | my ( $sgn, $ent, $frc, $exp ) = parse_num( $num, $self->{'DECIMAL'}, $self->{'SEPARADORES'} ); | ||
| 102 | |||
| 103 | my $gen = $self->{'GENERO'}; | ||
| 104 | $genf = $gen unless defined $genf; | ||
| 105 | $genm = $genf unless defined $genm; | ||
| 106 | |||
| 107 | # Convertir la parte entera ajustando el sexo | ||
| 108 | #my @words = cardinal_simple($ent, $exp, $self->{'UNMIL'}, $gen); | ||
| 109 | |||
| 110 | # Traducir la parte decimal de acuerdo al formato | ||
| 111 | for ( $self->{'FORMATO'} ) { | ||
| 112 | /%([0-9]*)s/ && do { | ||
| 113 | |||
| 114 | # Textual, se traduce según el genero | ||
| 115 | $frc = substr( '0' x $exp . $frc, 0, $1 ) if $1; | ||
| 116 | $frc = join( " ", fraccion_simple( $frc, $exp, $self->{'UNMIL'}, $genf, $genm ) ); | ||
| 117 | $frc = $frc ? sprintf( $self->{'FORMATO'}, $frc ) : ''; | ||
| 118 | last; | ||
| 119 | }; | ||
| 120 | /%([0-9]*)d/ && do { | ||
| 121 | |||
| 122 | # Numérico, se da formato a los dígitos | ||
| 123 | $frc = substr( '0' x $exp . $frc, 0, $1 ); | ||
| 124 | $frc = sprintf( $self->{'FORMATO'}, $frc ); | ||
| 125 | last; | ||
| 126 | }; | ||
| 127 | do { | ||
| 128 | |||
| 129 | # Sin formato, se ignoran los decimales | ||
| 130 | $frc = ''; | ||
| 131 | last; | ||
| 132 | }; | ||
| 133 | } | ||
| 134 | if ($ent) { | ||
| 135 | $ent = $self->cardinal( ( $sgn < 0 ? '-' : '+' ) . $ent ); | ||
| 136 | } | ||
| 137 | else { | ||
| 138 | $ent = 'cero'; | ||
| 139 | } | ||
| 140 | $ent .= ' ' . $frc if $ent and $frc; | ||
| 141 | return $self->retval($ent); | ||
| 142 | } | ||
| 143 | |||
| 144 | # }}} | ||
| 145 | # {{{ ordinal | ||
| 146 | |||
| 147 | sub ordinal { | ||
| 148 | my $self = shift; | ||
| 149 | my $num = shift; | ||
| 150 | my ( $sgn, $ent, $frc, $exp ) = parse_num( $num, $self->{'DECIMAL'}, $self->{'SEPARADORES'} ); | ||
| 151 | |||
| 152 | croak "Ordinal negativo" if $sgn < 0; | ||
| 153 | carp "Ordinal con decimales" if $frc; | ||
| 154 | |||
| 155 | if ( $ent =~ /^0*$/ ) { | ||
| 156 | carp "Ordinal cero"; | ||
| 157 | return ''; | ||
| 158 | } | ||
| 159 | |||
| 160 | my $text = join( " ", ordinal_simple( $ent, $exp, $self->{'GENERO'} ) ); | ||
| 161 | |||
| 162 | return $self->retval($text); | ||
| 163 | } | ||
| 164 | |||
| 165 | # }}} | ||
| 166 | # {{{ Build the accessors | ||
| 167 | |||
| 168 | { | ||
| 169 | my @a = @_; | ||
| 170 | my %names = ( ( map { $_ => $_ } keys %new_defaults ), %opt_alias ); | ||
| 171 | while ( my ( $opt, $alias ) = each %names ) { | ||
| 172 | $opt = lc $opt; | ||
| 173 | no strict 'refs'; ## no critic | ||
| 174 | *$opt = sub { | ||
| 175 | my $self = shift; | ||
| 176 | return $self->{$alias} unless @a; | ||
| 177 | $self->{$alias} = shift @a; | ||
| 178 | return $self; | ||
| 179 | } | ||
| 180 | } | ||
| 181 | } | ||
| 182 | |||
| 183 | # }}} | ||
| 184 | |||
| 185 | ##################################################################### | ||
| 186 | # | ||
| 187 | # Soporte para números CARDINALES | ||
| 188 | # | ||
| 189 | #################################################################### | ||
| 190 | # {{{ variable declarations II | ||
| 191 | |||
| 192 | my @cardinal_30 = qw/ cero un dos tres cuatro cinco seis siete ocho nueve diez | ||
| 193 | once doce trece catorce quince dieciséis diecisiete dieciocho diecinueve | ||
| 194 | veinte veintiun veintidós veintitrés veinticuatro veinticinco veintiséis | ||
| 195 | veintisiete veintiocho veintinueve /; | ||
| 196 | |||
| 197 | my @cardinal_dec = qw/ | ||
| 198 | 0 1 2 treinta cuarenta cincuenta sesenta setenta ochenta noventa /; | ||
| 199 | |||
| 200 | my @cardinal_centenas = ( | ||
| 201 | "", qw/ | ||
| 202 | ciento doscientos trescientos cuatrocientos quinientos | ||
| 203 | seiscientos setecientos ochocientos novecientos / | ||
| 204 | ); | ||
| 205 | |||
| 206 | my @cardinal_megas = ( | ||
| 207 | "", qw/ m b tr cuatr quint sext sept oct non dec undec | ||
| 208 | dudec tredec cuatordec quindec sexdec sepdec octodec novendec vigint / | ||
| 209 | ); | ||
| 210 | |||
| 211 | my $MAX_DIGITS = 6 * @cardinal_megas; | ||
| 212 | |||
| 213 | # }}} | ||
| 214 | # {{{ cardinal_e2 | ||
| 215 | |||
| 216 | sub cardinal_e2 { | ||
| 217 | my ( $n, $nn ) = @_; | ||
| 218 | |||
| 219 | return if $n == 0; | ||
| 220 | do { push @$nn, $cardinal_30[$n]; return } if $n < 30; | ||
| 221 | $n =~ /^(.)(.)$/; | ||
| 222 | push @$nn, $cardinal_30[$2], "y" if $2; | ||
| 223 | push @$nn, $cardinal_dec[$1]; | ||
| 224 | |||
| 225 | return; | ||
| 226 | } | ||
| 227 | |||
| 228 | # }}} | ||
| 229 | # {{{ cardinal_e3 | ||
| 230 | |||
| 231 | sub cardinal_e3 { | ||
| 232 | my ( $n, $nn ) = @_; | ||
| 233 | |||
| 234 | return if $n == 0; | ||
| 235 | $n == 100 and do { push @$nn, "cien"; return }; | ||
| 236 | cardinal_e2( $n % 100, $nn ); | ||
| 237 | $n >= 100 and push @$nn, $cardinal_centenas[ int( $n / 100 ) ]; | ||
| 238 | |||
| 239 | return; | ||
| 240 | } | ||
| 241 | |||
| 242 | # }}} | ||
| 243 | # {{{ cardinal_e6 | ||
| 244 | |||
| 245 | sub cardinal_e6 { | ||
| 246 | my ( $n, $nn, $mag, $un_mil, $postfix ) = @_; | ||
| 247 | |||
| 248 | return if $n == 0; | ||
| 249 | push @$nn, $cardinal_megas[$mag] . $postfix->[ $n == 1 ] if $mag; | ||
| 250 | cardinal_e3( $n % 1000, $nn ); | ||
| 251 | my $n3 = int( $n / 1000 ); | ||
| 252 | if ($n3) { | ||
| 253 | push @$nn, "mil"; | ||
| 254 | cardinal_e3( $n3, $nn ) if $n3 != 1 or $un_mil; | ||
| 255 | } | ||
| 256 | |||
| 257 | return; | ||
| 258 | } | ||
| 259 | |||
| 260 | # }}} | ||
| 261 | # {{{ cardinal_generic | ||
| 262 | |||
| 263 | sub cardinal_generic { | ||
| 264 | my ( $n, $exp, $fmag, $gen ) = @_; | ||
| 265 | $gen //= ''; | ||
| 266 | |||
| 267 | $n =~ s/^0*//; # eliminar ceros a la izquierda | ||
| 268 | return () unless $n; | ||
| 269 | croak("Fuera de rango") if length($n) + $exp > $MAX_DIGITS; | ||
| 270 | $n .= "0" x ( $exp % 6 ); # agregar ceros a la derecha | ||
| 271 | my $mag = int( $exp / 6 ); | ||
| 272 | my @group = (); | ||
| 273 | $fmag->( $1, \@group, $mag++ ) while $n =~ s/(.{1,6})$//x; | ||
| 274 | $group[0] .= $gen if $group[0] =~ /un$/; | ||
| 275 | return reverse @group; | ||
| 276 | } | ||
| 277 | |||
| 278 | # }}} | ||
| 279 | # {{{ cardinal_simple | ||
| 280 | |||
| 281 | sub cardinal_simple { | ||
| 282 | my ( $n, $exp, $un_mil, $gen ) = @_; | ||
| 283 | |||
| 284 | $un_mil = $un_mil ? 1 : 0; | ||
| 285 | $gen = $NEUTRAL unless $gen; | ||
| 286 | my $format = sub { | ||
| 287 | cardinal_e6( $_[0], $_[1], $_[2], $un_mil, [ 'illones', 'illón' ] ); | ||
| 288 | }; | ||
| 289 | return cardinal_generic( $n, $exp, $format, $gen ); | ||
| 290 | } | ||
| 291 | |||
| 292 | # }}} | ||
| 293 | # {{{ fraccion_mag_prefix | ||
| 294 | |||
| 295 | sub fraccion_mag_prefix { | ||
| 296 | my ( $mag, $gp ) = @_; | ||
| 297 | |||
| 298 | return "" unless $mag; | ||
| 299 | return "décim" . $gp if $mag == 1; | ||
| 300 | return "centésim" . $gp if $mag == 2; | ||
| 301 | my $format = sub { | ||
| 302 | cardinal_e6( $_[0], $_[1], $_[2], 0, [ 'illon', 'illon' ] ); | ||
| 303 | }; | ||
| 304 | my @name = cardinal_generic( 1, $mag, $format, "" ); | ||
| 305 | shift @name unless $mag % 6; | ||
| 306 | return join( "", @name, "ésim", $gp ); | ||
| 307 | } | ||
| 308 | |||
| 309 | # }}} | ||
| 310 | # {{{ fraccion_simple | ||
| 311 | |||
| 312 | sub fraccion_simple { | ||
| 313 | my ( $n, $exp, $un_mil, $gen, $ngen ) = @_; | ||
| 314 | |||
| 315 | $n =~ s/0*$//; # eliminar 0 a la derecha | ||
| 316 | return () if $n == 0; | ||
| 317 | $ngen = $gen unless defined $ngen; | ||
| 318 | $exp = -$exp + length $n; # adjust exponent | ||
| 319 | croak("Fuera de rango") if $exp > $MAX_DIGITS; | ||
| 320 | $gen .= "s" unless $n =~ /^0*1$/; | ||
| 321 | return ( cardinal_simple( $n, 0, $un_mil, $ngen ), fraccion_mag_prefix( $exp, $gen ) ); | ||
| 322 | } | ||
| 323 | |||
| 324 | # }}} | ||
| 325 | ##################################################################### | ||
| 326 | # | ||
| 327 | # Soporte para números ORDINALES | ||
| 328 | # | ||
| 329 | #################################################################### | ||
| 330 | # {{{ variable declarations III | ||
| 331 | |||
| 332 | my @ordinal_13 = ( | ||
| 333 | '', qw/ primer_ segund_ tercer_ cuart_ quint_ sext_ | ||
| 334 | séptim_ octav_ noven_ décim_ undécim_ duodécim_ / | ||
| 335 | ); | ||
| 336 | |||
| 337 | my @ordinal_dec = qw/ 0 1 vi tri cuadra quicua sexa septua octo nona /; | ||
| 338 | |||
| 339 | my @ordinal_cen = qw/ 0 c duoc tric cuadring quing sexc septig octing noning /; | ||
| 340 | |||
| 341 | # }}} | ||
| 342 | # {{{ ordinal_e2 | ||
| 343 | |||
| 344 | sub ordinal_e2 { | ||
| 345 | my ( $n, $nn ) = @_; | ||
| 346 | |||
| 347 | return if $n == 0; | ||
| 348 | if ( $n < 13 ) { | ||
| 349 | push @$nn, $ordinal_13[$n]; | ||
| 350 | return; | ||
| 351 | } | ||
| 352 | $n =~ /^(.)(.)$/; | ||
| 353 | my $lo = $ordinal_13[$2]; | ||
| 354 | if ( $1 <= 2 ) { | ||
| 355 | my $name = $2 | ||
| 356 | ? ( $1 == 1 ? 'decimo' : 'vigesimo' ) | ||
| 357 | : ( $1 == 1 ? 'décim_' : 'vigésim_' ); | ||
| 358 | $name =~ s/o$// if $2 == 8; # special case vowels colapsed | ||
| 359 | push @$nn, $name . $lo; | ||
| 360 | return; | ||
| 361 | } | ||
| 362 | push @$nn, $lo if $2; | ||
| 363 | push @$nn, $ordinal_dec[$1] . 'gésim_'; | ||
| 364 | return; | ||
| 365 | } | ||
| 366 | |||
| 367 | # }}} | ||
| 368 | # {{{ ordinal_e3 | ||
| 369 | |||
| 370 | sub ordinal_e3 { | ||
| 371 | my ( $n, $nn ) = @_; | ||
| 372 | |||
| 373 | return if $n == 0; | ||
| 374 | ordinal_e2( $n % 100, $nn ); | ||
| 375 | push @$nn, $ordinal_cen[ int( $n / 100 ) ] . 'entésim_' if $n > 99; | ||
| 376 | |||
| 377 | return; | ||
| 378 | } | ||
| 379 | |||
| 380 | # }}} | ||
| 381 | # {{{ ordinal_e6 | ||
| 382 | |||
| 383 | sub ordinal_e6 { | ||
| 384 | my ( $n, $nn, $mag ) = @_; | ||
| 385 | |||
| 386 | return if $n == 0; | ||
| 387 | push @$nn, $cardinal_megas[$mag] . 'illonésim_' if $mag; | ||
| 388 | ordinal_e3( $n % 1000, $nn ); | ||
| 389 | my $n3 = int( $n / 1000 ); | ||
| 390 | if ($n3) { | ||
| 391 | if ( $n3 > 1 ) { | ||
| 392 | my $pos = @$nn; # keep pos to adjust number | ||
| 393 | cardinal_e3( $n3, $nn ); # this is not a typo, its cardinal | ||
| 394 | $nn->[$pos] .= 'milésim_'; | ||
| 395 | } | ||
| 396 | else { | ||
| 397 | push @$nn, "milésim_"; | ||
| 398 | } | ||
| 399 | } | ||
| 400 | |||
| 401 | return; | ||
| 402 | } | ||
| 403 | |||
| 404 | # }}} | ||
| 405 | # {{{ ordinal_simple | ||
| 406 | |||
| 407 | sub ordinal_simple { | ||
| 408 | my ( $n, $exp, $gen ) = @_; | ||
| 409 | |||
| 410 | $n =~ s/^0*//; # eliminar ceros a la izquierda | ||
| 411 | return () unless $n; | ||
| 412 | croak("Fuera de rango") if length($n) + $exp > $MAX_DIGITS; | ||
| 413 | $n .= "0" x ( $exp % 6 ); # agregar ceros a la derecha | ||
| 414 | my $mag = int( $exp / 6 ); | ||
| 415 | |||
| 416 | my @group = (); | ||
| 417 | if ( $mag == 0 ) { | ||
| 418 | $n =~ s/(.{1,6})$//x; | ||
| 419 | ordinal_e6( $1, \@group, $mag++ ); | ||
| 420 | } | ||
| 421 | |||
| 422 | while ( $n =~ s/(.{1,6})$//x ) { | ||
| 423 | if ( $1 == 0 ) { | ||
| 424 | $mag++; | ||
| 425 | next; | ||
| 426 | } | ||
| 427 | my $words = []; | ||
| 428 | if ( $1 == 1 ) { | ||
| 429 | push @$words, ''; | ||
| 430 | } | ||
| 431 | else { | ||
| 432 | cardinal_e6( $1, $words, 0, 0, [] ); | ||
| 433 | } | ||
| 434 | $words->[0] .= $cardinal_megas[ $mag++ ] . 'illonésim_'; | ||
| 435 | push @group, @$words; | ||
| 436 | } | ||
| 437 | |||
| 438 | unless ($gen) { | ||
| 439 | $group[0] =~ s/r_$/r/; # Ajustar neutros en 1er, 3er, etc. | ||
| 440 | $gen = $MALE; | ||
| 441 | } | ||
| 442 | s/_/$gen/g for @group; | ||
| 443 | return reverse @group; | ||
| 444 | } | ||
| 445 | |||
| 446 | # }}} | ||
| 447 | # {{{ parse_num | ||
| 448 | |||
| 449 | sub parse_num { | ||
| 450 | my ( $num, $dec, $sep ) = @_; | ||
| 451 | |||
| 452 | # Eliminar blancos y separadores | ||
| 453 | $num =~ s/[\s\Q$sep\E]//g; | ||
| 454 | $dec = '\\' . $dec if $dec eq '.'; | ||
| 455 | my ( $sgn, $int, $frc, $exp ) = $num =~ /^ | ||
| 456 | ([+-]?) (?= \d | $dec\d ) # signo | ||
| 457 | (\d*) # parte entera | ||
| 458 | (?: $dec (\d*) )? # parte decimal | ||
| 459 | (?: [Ee] ([+-]?\d+) )? # exponente | ||
| 460 | $/x or croak("Error de sintaxis"); | ||
| 461 | |||
| 462 | $sgn = $sgn eq '-' ? -1 : 1; # ajustar signo | ||
| 463 | return ( $sgn, $int || 0, $frc || 0, $exp ) unless $exp ||= 0; | ||
| 464 | |||
| 465 | $int ||= ''; | ||
| 466 | $frc ||= ''; | ||
| 467 | |||
| 468 | # reducir la magnitud del exponente | ||
| 469 | if ( $exp > 0 ) { | ||
| 470 | if ( $exp > length $frc ) { | ||
| 471 | $exp -= length $frc; | ||
| 472 | $int .= $frc; | ||
| 473 | $frc = ''; | ||
| 474 | } | ||
| 475 | else { | ||
| 476 | $int .= substr( $frc, 0, $exp ); | ||
| 477 | $frc = substr( $frc, $exp ); | ||
| 478 | $exp = 0; | ||
| 479 | } | ||
| 480 | } | ||
| 481 | else { | ||
| 482 | if ( -$exp > length $int ) { | ||
| 483 | $exp += length $int; | ||
| 484 | $frc = $int . $frc; | ||
| 485 | $int = ''; | ||
| 486 | } | ||
| 487 | else { | ||
| 488 | $frc = substr( $int, $exp + length $int ) . $frc; | ||
| 489 | $int = substr( $int, 0, $exp + length $int ); | ||
| 490 | $exp = 0; | ||
| 491 | } | ||
| 492 | } | ||
| 493 | return ( $sgn, $int || 0, $frc || 0, $exp ); | ||
| 494 | } | ||
| 495 | |||
| 496 | # }}} | ||
| 497 | # {{{ retval | ||
| 498 | |||
| 499 | sub retval { | ||
| 500 | my $self = shift; | ||
| 501 | my $rv = shift; | ||
| 502 | if ( $self->{ACENTOS} ) { | ||
| 503 | if ( $self->{HTML} ) { | ||
| 504 | $rv =~ s/([áéíóú])/&$1acute;/g; | ||
| 505 | $rv =~ tr/áéíóú/aeiou/; | ||
| 506 | } | ||
| 507 | } | ||
| 508 | else { | ||
| 509 | $rv =~ tr/áéíóú/aeiou/; | ||
| 510 | } | ||
| 511 | return $self->{MAYUSCULAS} ? uc $rv : $rv; | ||
| 512 | } | ||
| 513 | |||
| 514 | # }}} | ||
| 515 | |||
| 516 | |||
| 517 | # {{{ num2spa_ordinal standalone ordinal conversion | ||
| 518 | |||
| 519 | sub num2spa_cardinal :Export { | ||
| 520 | my $number = shift; | ||
| 521 | my $obj = Lingua::SPA::Num2Word->new(); | ||
| 522 | return $obj->cardinal($number); | ||
| 523 | } | ||
| 524 | |||
| 525 | sub num2spa_ordinal :Export { | ||
| 526 | my $number = shift; | ||
| 527 | |||
| 528 | croak 'You should specify a positive integer' | ||
| 529 | unless defined $number and $number =~ /^\d+$/ and $number > 0; | ||
| 530 | |||
| 531 | my $obj = Lingua::SPA::Num2Word->new( GENERO => 'o' ); | ||
| 532 | return $obj->ordinal($number); | ||
| 533 | } | ||
| 534 | |||
| 535 | # }}} | ||
| 536 | # {{{ capabilities declare supported features | ||
| 537 | |||
| 538 | sub capabilities { | ||
| 539 | return { | ||
| 540 | cardinal => 1, | ||
| 541 | ordinal => 1, | ||
| 542 | }; | ||
| 543 | } | ||
| 544 | |||
| 545 | # }}} | ||
| 546 | 1; | ||
| 547 | __END__ |