| 1 | # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8; -*- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Lingua::GLE::Num2Word; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: This module converts numbers (cardinals) into their Irish (Gaeilge) equivalents using the modern decimal counting system. It accepts positive integers up to, but not including, 1 billion. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Export::Attrs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # {{{ variable declarations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | our $VERSION = '0.2603270'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # Irish (Gaeilge) uses a decimal counting system in modern usage. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # The counting form uses the "a" prefix before unit digits. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # Going up to 999_999_999. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | my @units = qw(náid a_haon a_dó a_trí a_ceathair a_cúig a_sé a_seacht a_hocht a_naoi); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | my @tens = (undef, 'a_deich', 'fiche', 'tríocha', 'daichead', 'caoga', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 'seasca', 'seachtó', 'ochtó', 'nócha'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # {{{ num2gle_cardinal convert number to text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | sub num2gle_cardinal :Export { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 23 | ▶ | my $num = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
num2gle_cardinal: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 23 | ▶ | croak 'You should specify a number from interval [0, 999_999_999]' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
not defined $num && $num =~ /\A\d+\z/msux or $num < 0 or $num > 999999999
not defined $num && $num =~ /\A\d+\z/msux or $num < 0
defined $num && $num =~ /\A\d+\z/msux
MC/DC50%2/4
not defined $num && $num =~ /\A\d+\z/msux or $num < 0 or $num > 999999999
defined $num
$num =~ /\A\d+\z/msux
$num < 0
$num > 999999999
Truth table60%3/5
not(A && B) or C or D
A= defined $numB= $num =~ /\A\d+\z/msuxC= $num < 0D= $num > 999999999
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | if !defined $num | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | || $num !~ m{\A\d+\z}xms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | || $num < 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | || $num > 999_999_999; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # Zero | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 21 | ▶ | return 'náid' if $num == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 20 | my @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # Millions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 20 | ▶ | if ($num >= 1_000_000) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 2 | my $millions = int($num / 1_000_000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | ▶ | push @parts, _cardinal_below_1000($millions) if $millions > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | push @parts, 'milliún'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | $num %= 1_000_000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # Thousands | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 20 | ▶ | if ($num >= 1000) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 3 | my $thousands = int($num / 1000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | ▶ | push @parts, _cardinal_below_1000($thousands) if $thousands > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 3 | push @parts, 'míle'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 3 | $num %= 1000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # Remainder below 1000 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 20 | ▶ | if ($num > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 17 | push @parts, _cardinal_below_1000($num); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 20 | my $result = join(' ', @parts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 20 | $result =~ s/_/ /g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 20 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # {{{ _cardinal_below_1000 internal: handle 1-999 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | sub _cardinal_below_1000 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 19 | ▶ | my $num = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cardinal_below_1000: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 19 | ▶ | return if $num == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 19 | my @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # Hundreds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 19 | ▶ | if ($num >= 100) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 5 | my $h = int($num / 100); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 5 | ▶ | if ($h == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | push @parts, 'céad'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 3 | push @parts, $units[$h], 'céad'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 5 | $num %= 100; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # Tens and units | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 19 | ▶ | if ($num > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 17 | push @parts, _cardinal_below_100($num); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 19 | return @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # {{{ _cardinal_below_100 internal: handle 1-99 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | sub _cardinal_below_100 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 17 | ▶ | my $num = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cardinal_below_100: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 17 | ▶ | return if $num == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # 1-9: counting form | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 17 | ▶ | if ($num < 10) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 4 | return $units[$num]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # 10: a deich | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 13 | ▶ | if ($num == 10) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | return 'a_deich'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # 11-19: unit + déag (12 uses dhéag) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 12 | ▶ | if ($num < 20) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 3 | my $u = $num - 10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 3 | ▶ | my $deag = ($u == 2) ? 'dhéag' : 'déag'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 3 | return $units[$u] . ' ' . $deag; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # 20-99 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 9 | my $t = int($num / 10); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 9 | my $u = $num % 10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 9 | ▶ | if ($u == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 2 | return $tens[$t]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # tens + a + unit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 7 | return $tens[$t] . ' ' . $units[$u]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # {{{ capabilities declare supported features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | sub capabilities { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | cardinal => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
capabilities: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | ordinal => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||