| 1 | # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8 -*- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Lingua::SQI::Num2Word; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Number to word conversion in Albanian | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 1 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # {{{ variable declarations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | my Readonly::Scalar $COPY = 'Copyright (c) PetaMem, s.r.o. 2002-present'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | our $VERSION = '0.2603270'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # {{{ num2sqi_cardinal convert number to text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | sub num2sqi_cardinal :Export { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 35 | ▶ | my $positive = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
num2sqi_cardinal: called CC=22 SCAR=31.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 35 | ▶ | croak 'You should specify a number from interval [0, 999_999_999]' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
not defined $positive && $positive =~ /\A\d+\z/msux or $positive < 0 or $positive > 999999999
not defined $positive && $positive =~ /\A\d+\z/msux or $positive < 0
defined $positive && $positive =~ /\A\d+\z/msux
MC/DC50%2/4
not defined $positive && $positive =~ /\A\d+\z/msux or $positive < 0 or $positive > 999999999
defined $positive
$positive =~ /\A\d+\z/msux
$positive < 0
$positive > 999999999
Truth table60%3/5
not(A && B) or C or D
A= defined $positiveB= $positive =~ /\A\d+\z/msuxC= $positive < 0D= $positive > 999999999
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | if !defined $positive | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | || $positive !~ m{\A\d+\z}xms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | || $positive < 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | || $positive > 999_999_999; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 33 | my @ones = qw(zero një dy tre katër pesë gjashtë shtatë tetë nëntë); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 33 | my @teens = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | dhjetë njëmbëdhjetë dymbëdhjetë trembëdhjetë katërmbëdhjetë | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | pesëmbëdhjetë gjashtëmbëdhjetë shtatëmbëdhjetë tetëmbëdhjetë nëntëmbëdhjetë | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 33 | my @tens = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | _invalid _invalid njëzet tridhjetë dyzet pesëdhjetë | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | gjashtëdhjetë shtatëdhjetë tetëdhjetë nëntëdhjetë | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 33 | ▶ | return $ones[$positive] if ($positive >= 0 && $positive < 10); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$positive >= 0 and $positive < 10
MC/DC50%1/2
$positive >= 0 and $positive < 10
$positive >= 0
$positive < 10
Truth table66%2/3
A and B
A= $positive >= 0B= $positive < 10
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 24 | ▶ | return $teens[$positive - 10] if ($positive >= 10 && $positive < 20); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$positive >= 10 and $positive < 20
MC/DC50%1/2
$positive >= 10 and $positive < 20
$positive >= 10
$positive < 20
Truth table66%2/3
A and B
A= $positive >= 10B= $positive < 20
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 21 | my $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | my $remain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 21 | ▶ | if ($positive >= 20 && $positive < 100) { # 20 .. 99 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition66%2/3
$positive >= 20 and $positive < 100
MC/DC50%1/2
$positive >= 20 and $positive < 100
$positive >= 20
$positive < 100
Truth table66%2/3
A and B
A= $positive >= 20B= $positive < 100
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 8 | my $ten_idx = int($positive / 10); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 8 | $remain = $positive % 10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 8 | $out = $tens[$ten_idx]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 8 | ▶ | $out .= ' e ' . $ones[$remain] if ($remain); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | ▶ | elsif ($positive >= 100 && $positive < 1000) { # 100 .. 999 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$positive >= 100 and $positive < 1000
MC/DC50%1/2
$positive >= 100 and $positive < 1000
$positive >= 100
$positive < 1000
Truth table66%2/3
A and B
A= $positive >= 100B= $positive < 1000
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 6 | my $hund_idx = int($positive / 100); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 6 | $remain = $positive % 100; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 6 | $out = $ones[$hund_idx] . 'qind'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 6 | ▶ | $out .= ' e ' . num2sqi_cardinal($remain) if ($remain); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | ▶ | elsif ($positive >= 1000 && $positive < 1_000_000) { # 1000 .. 999_999 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$positive >= 1000 and $positive < 1000000
MC/DC50%1/2
$positive >= 1000 and $positive < 1000000
$positive >= 1000
$positive < 1000000
Truth table66%2/3
A and B
A= $positive >= 1000B= $positive < 1000000
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 4 | my $kilo_idx = int($positive / 1000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 4 | $remain = $positive % 1000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 4 | $out = num2sqi_cardinal($kilo_idx) . ' mijë'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 4 | ▶ | $out .= ' e ' . num2sqi_cardinal($remain) if ($remain); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | ▶ | elsif ($positive >= 1_000_000 && $positive < 1_000_000_000) { # 1_000_000 .. 999_999_999 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$positive >= 1000000 and $positive < 1000000000
MC/DC0%0/2
$positive >= 1000000 and $positive < 1000000000
$positive >= 1000000
$positive < 1000000000
Truth table33%1/3
A and B
A= $positive >= 1000000B= $positive < 1000000000
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 3 | my $mega_idx = int($positive / 1_000_000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 3 | $remain = $positive % 1_000_000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 3 | $out = num2sqi_cardinal($mega_idx); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 3 | ▶ | $out .= $mega_idx == 1 ? ' milion' : ' milionë'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 3 | ▶ | $out .= ' e ' . num2sqi_cardinal($remain) if ($remain); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 21 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # {{{ capabilities declare supported features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | sub capabilities { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | cardinal => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
capabilities: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | ordinal => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||