blib/lib/Lingua/IND/Numbers.pm

filter: Statementstmt 100% 56 / 56 Branchbran 95.8% 23 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 1 / 1 totaltotal 98.9% 90 / 91 CC 13 SCAR 20.9
CC
13
Cov
99%
to_string
13.0
BEGIN
1.0
BEGIN
1.0
CRAP 8.1
↑ Summary
1 package Lingua::IND::Numbers;
2  
3 5 $Lingua::IND::Numbers::VERSION = '0.10';
4 5 $Lingua::IND::Numbers::AUTHORITY = 'cpan:MANWAR';
5  
6 =head1 NAME
7  
8 Lingua::IND::Numbers - Indian Numbering System representation
9  
10 =head1 VERSION
11  
12 Version 0.10
13  
14 =cut
15  
16 5 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 5 ▶use bignum;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 2 ▶has 'chart' => (is => 'ro', default => sub { _get_chart() });
Subroutine __ANON__: called CC=1 SCAR=0.0
24 2 ▶has 'units' => (is => 'ro', default => sub { _get_units() });
Subroutine __ANON__: called CC=1 SCAR=0.0
25  
26 =head1 DESCRIPTION
27  
28 The Indian Numbering System is used India, Pakistan, Bangladesh, Nepal, and Sri
29 Lanka. It is based on the Vedic numbering system in which numbers over 9,999 are
30 written in two-digit groups (or a mix of two- and three-digit groups) rather than
31 the three-digit groups used in most other parts of the world. In Pakistan,they do
32 not use this numbering system in English media but only in Urdu & other regional
33 languages.
34  
35 The terms lakh (100,000) and crore (10,000,000) are used in Indian English to
36 express large numbers.
37  
38 +------------------------------------+--------------------------------------+
39 | Name | Indian Figure |
40 +------------------------------------+--------------------------------------+
41 | Shunya (Zero) | 0 |
42 | Ek (One) | 1 |
43 | Das (Ten) | 10 |
44 | Sau (One Hundres) | 100 |
45 | Hazaar (One Thousand) | 1,000 |
46 | Das Hazaar (Ten Thousand) | 10,000 |
47 | Lakh (Hundred Thousand) | 1,00,000 |
48 | Das Lakh | 10,00,000 |
49 | Crore | 1,00,00,000 |
50 | Das Crore | 10,00,00,000 |
51 | Arab (One Hundred Crore) | 1,00,00,00,000 |
52 | Das Arab (One Thousand Crore) | 10,00,00,00,000 |
53 | Kharab (Ten Thousand Crore) | 1,00,00,00,00,000 |
54 | Das Kharab (One Lakh Crore) | 10,00,00,00,00,000 |
55 | Neel (Ten Lakh Crore) | 1,00,00,00,00,00,000 |
56 | Das Neel (One Crore Crore) | 10,00,00,00,00,00,000 |
57 | Padm (Ten Crore Crore) | 1,00,00,00,00,00,00,000 |
58 | Das Padm (One Hundred Crore Crore) | 10,00,00,00,00,00,00,000 |
59 | Shankh (One Lakh Lakh Crore) | 1,00,00,00,00,00,00,00,000 |
60 +------------------------------------+--------------------------------------+
61  
62 Source: L<wikipedia|http://en.wikipedia.org/wiki/Indian_Numbering_System>
63  
64 =head1 NUMBERS
65  
66 For example, 150000 becomes Ek Lakh Pachaas Hazar.
67  
68 +------------+--------+ +------------+--------+ +----------+---------+
69 | Name | Number | | Name | Number | | Name | Number |
70 +------------+--------+ +------------+--------+ +----------+---------+
71 | Ek | 1 | | Egyarah | 11 | | Ekees | 21 |
72 | Do | 2 | | Barah | 12 | | Baees | 22 |
73 | Teen | 3 | | Terah | 13 | | Teyees | 23 |
74 | Chaar | 4 | | Chaudah | 14 | | Chaubees | 24 |
75 | Paanch | 5 | | Pandrah | 15 | | Pachees | 25 |
76 | Chhe | 6 | | Solah | 16 | | Chhabbis | 26 |
77 | Saat | 7 | | Satrah | 17 | | Satayees | 27 |
78 | Aath | 8 | | Attharah | 18 | | Atthaees | 28 |
79 | Nau | 9 | | Unnees | 19 | | Untees | 29 |
80 | Das | 10 | | Bees | 20 | | Tees | 30 |
81 +------------+--------+ +------------+--------+ +----------+---------+
82  
83 +------------+--------+ +------------+--------+ +-----------+--------+
84 | Name | Number | | Name | Number | | Name | Number |
85 +------------+--------+ +------------+--------+ +-----------+--------+
86 | Ektees | 31 | | Ektalees | 41 | | Ekaawan | 51 |
87 | Battees | 32 | | Beyalees | 42 | | Baawan | 52 |
88 | Taitees | 33 | | Taitalees | 43 | | Tirpan | 53 |
89 | Chautees | 34 | | Chaualees | 44 | | Chauwan | 54 |
90 | Paitees | 35 | | Paitalees | 45 | | Pachpan | 55 |
91 | Chhattess | 36 | | Chheyalees | 46 | | Chhappan | 56 |
92 | Saitees | 37 | | Saitalees | 47 | | Santawan | 57 |
93 | Artees | 38 | | Artalees | 48 | | Anthawan | 58 |
94 | Unchalees | 39 | | Unchaas | 49 | | Unsath | 59 |
95 | Chalees | 40 | | Pachaas | 50 | | Saath | 60 |
96 +------------+--------+ +------------+--------+ +-----------+------- +
97  
98 +------------+--------+ +------------+--------+ +-----------+--------+
99 | Name | Number | | Name | Number | | Name | Number |
100 +------------+--------+ +------------+--------+ +-----------+--------+
101 | Eksath | 61 | | Ekhattar | 71 | | Ekaase | 81 |
102 | Baasath | 62 | | Bahattar | 72 | | Beraase | 82 |
103 | Tirsath | 63 | | Tehattar | 73 | | Teraase | 83 |
104 | Chausath | 64 | | Chauhattar | 74 | | Chauraase | 84 |
105 | Paisath | 65 | | Pachhattar | 75 | | Pachaase | 85 |
106 | Chheyasath | 66 | | Chheyattar | 76 | | Chheyaase | 86 |
107 | Sarsath | 67 | | Satattar | 77 | | Sataase | 87 |
108 | Arsath | 68 | | Atathar | 78 | | Atthaase | 88 |
109 | Unhattar | 69 | | Unnase | 79 | | Nawaase | 89 |
110 | Sattar | 70 | | Asse | 80 | | Nabbe | 90 |
111 +------------+--------+ +------------+--------+ +-----------+--------+
112  
113 +------------+--------+
114 | Name | Number |
115 +------------+--------+
116 | Ekkaanwe | 91 |
117 | Beraanwe | 92 |
118 | Teraanwe | 93 |
119 | Chauraanwe | 94 |
120 | Panchaanwe | 95 |
121 | Chheyaanwe | 96 |
122 | Santaanwe | 97 |
123 | Anthaanwe | 98 |
124 | Neenaanwe | 99 |
125 +------------+--------+
126  
127 =head1 METHODS
128  
129 =head2 to_string($number)
130  
131 It returns the number represented in the Indian Numbering System.
132  
133 use strict; use warnings;
134 use Lingua::IND::Numbers;
135  
136 my $number = Lingua::IND::Numbers->new;
137 my $input = 123456;
138  
139 print "[$input]: ", $number->to_string($input), "\n";
140  
141 =cut
142  
143 sub to_string {
144 37 ▶ my ($self, $arg) = @_;
Subroutine to_string: called CC=13 SCAR=25.7
Pod documented
145  
146 37 ▶ die "ERROR: Undefined number.\n" unless defined $arg;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg 1 36 37
147 36 ▶ die "ERROR: Invalid number [$arg].\n" unless ($arg =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $arg =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/ 2 34 36
148 34 ▶ die "ERROR: Only positive number.\n" unless ($arg >= 0);
Branch: 1 branch
BranchTrueFalseTotal
unless $arg >= bless( {"sign" => "+","value" => bless( [0], 'Math::BigInt::Calc' )}, 'Math::BigInt' ) 1 33 34
149  
150 33 ▶ return 'Shunya' if ($arg == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $arg == bless( {"sign" => "+","value" => bless( [0], 'Math::BigInt::Calc' )}, 'Math::BigInt' ) 1 32 33
151  
152 32 my $chart = $self->chart;
153 32 my $units = $self->units;
154 32 my $number = ($arg + 0)->bstr();
155 32 ▶ die "ERROR: No decimal number [$arg].\n" if ($number =~ /\./);
Branch: 1 branch
BranchTrueFalseTotal
if $number =~ /\./ 1 31 32
156 31 my $size = length($number);
157 31 ▶ die "ERROR: No representation in Indian Numbering System.\n" if ($size > 18);
Branch: 1 branch
BranchTrueFalseTotal
if $size > bless( {"sign" => "+","value" => bless( [18], 'Math::BigInt::Calc' )}, 'Math::BigInt' ) 1 30 31
158  
159 30 my @digits = split //, $number;
160 30 my $string = '';
161 30 my $index = 0;
162  
163 30 ▶ while ($size >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size >= bless( {"sign" => "+","value" => bless( [1], 'Math::BigInt::Calc' )}, 'Math::BigInt' )) 69 0 69
164 69 ▶ if ($size > 3) {
Branch: 2 branches
BranchTrueFalseTotal
if ($size > {sign => '+', value => ['3']}) { } 49 20 69
elsif ($size == {sign => '+', value => ['3']}) { } 9 11 20
165 49 ▶ if ($size % 2 == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size % {sign => '+', value => ['2']} == {sign => '+', value => ['0']}) { } 14 35 49
166 14 $index = $digits[0];
167 14 $string .= sprintf("%s %s ", $chart->[$index], $units->{$size});
168 14 $number = (join '', @digits[1..($size-1)]) + 0;
169 }
170 else {
171 35 $index = sprintf("%d%d" , $digits[0], $digits[1]);
172 35 $string .= sprintf("%s %s ", $chart->[$index], $units->{$size});
173 35 $number = (join '', @digits[2..($size-1)]) + 0;
174 }
175 }
176 elsif ($size == 3) {
177 9 $string .= sprintf("%s %s ", $chart->[$digits[0]], $units->{$size});
178 9 $number = (join '', @digits[1..2]) + 0;
179 }
180 else {
181 11 ▶ ($size == 2)
Branch: 1 branch
BranchTrueFalseTotal
$size == {sign => '+', value => ['2']} ? : 5 6 11
182 ?
183 ($index = sprintf("%d%d", $digits[0], $digits[1]))
184 :
185 ($index = sprintf("%d", $digits[0]));
186 11 $string .= sprintf("%s", $chart->[$index]);
187  
188 11 return $string;
189 }
190  
191 58 ▶ if ($number > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($number > {sign => '+', value => ['0']}) { } 39 19 58
192 39 @digits = split //,$number;
193 39 $size = scalar(@digits);
194 }
195 else {
196 19 $string =~ s/\s+$//;
197 19 return $string;
198 }
199 }
200 }
201  
202 #
203 #
204 # PRIVATE METHODS
205  
206 sub _get_chart {
207  
208 return [
209 2 ▶ '',
Subroutine _get_chart: called CC=1 SCAR=0.0
210 qw/Ek Do Teen Chaar Paanch Chhe Saat Aath Nau Das
211 Egyarah Barah Terah Chaudah Pandrah Solah Satrah Attharah Unnees Bees
212 Ekees Baees Teyees Chaubees Pachees Chhabbees Satayees Atthaees Untees Tees
213 Ektees Battees Taithees Chautees Paitees Chhattees Saitees Artees Unchalees Chalees
214 Ektalees Beyalees Taitalees Chaualees Paitalees Chheyalees Saitalees Artalees Unchaas Pachaas
215 Ekaawan Baawan Tirpan Chauwan Pachpan Chhappan Santawan Anthawan Unsath Saath
216 Eksath Baasath Tirsath Chausath Paisath Chheyasath Sarsath Arsath Unhattar Sattar
217 Ekhattar Bahattar Tehattar Chauhattar Pachhattar Chheyattar Satattar Atathar Unnase Asse
218 Ekaase Beraase Teraase Chauraase Pachaase Chheyaasee Sataase Atthaase Nawaase Nabbe
219 Ekkaanwe Beraanwe Teraanwe Chauraanwe Panchaanwe Chheyaanwe Santaanwe Anthaanwe Neenaanwe/];
220 }
221  
222 sub _get_units {
223  
224 return {
225 2 ▶ 18 => 'Shankh', 17 => 'Padm' , 16 => 'Padm' , 15 => 'Neel',
Subroutine _get_units: called CC=1 SCAR=0.0
226 14 => 'Neel' , 13 => 'Kharab', 12 => 'Kharab', 11 => 'Arab',
227 10 => 'Arab' , 9 => 'Crore' , 8 => 'Crore' , 7 => 'Lakh',
228 6 => 'Lakh' , 5 => 'Hazaar', 4 => 'Hazaar', 3 => 'Sau' };
229 }
230  
231 =head1 AUTHOR
232  
233 Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
234  
235 =head1 REPOSITORY
236  
237 L<https://github.com/manwar/Lingua-IND-Numbers>
238  
239 =head1 BUGS
240  
241 Please report any bugs/feature requests to C<bug-lingua-ind-numbers at rt.cpan.org> or
242 through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Lingua-IND-Numbers>.
243 I will be notified & then you'll automatically be notified of progress on your bug
244 as I make changes.
245  
246 =head1 SUPPORT
247  
248 You can find documentation for this module with the perldoc command.
249  
250 perldoc Lingua::IND::Numbers
251  
252 You can also look for information at:
253  
254 =over 4
255  
256 =item * RT: CPAN's request tracker
257  
258 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Lingua-IND-Numbers>
259  
260 =item * AnnoCPAN: Annotated CPAN documentation
261  
262 L<http://annocpan.org/dist/Lingua-IND-Numbers>
263  
264 =item * CPAN Ratings
265  
266 L<http://cpanratings.perl.org/d/Lingua-IND-Numbers>
267  
268 =item * Search CPAN
269  
270 L<http://search.cpan.org/dist/Lingua-IND-Numbers/>
271  
272 =back
273  
274 =head1 LICENSE AND COPYRIGHT
275  
276 Copyright (C) 2014 - 2015 Mohammad S Anwar.
277  
278 This program is free software; you can redistribute it and/or modify it under
279 the terms of the the Artistic License (2.0). You may obtain a copy of the full
280 license at:
281  
282 L<http://www.perlfoundation.org/artistic_license_2_0>
283  
284 Any use, modification, and distribution of the Standard or Modified Versions is
285 governed by this Artistic License.By using, modifying or distributing the Package,
286 you accept this license. Do not use, modify, or distribute the Package, if you do
287 not accept this license.
288  
289 If your Modified Version has been derived from a Modified Version made by someone
290 other than you,you are nevertheless required to ensure that your Modified Version
291 complies with the requirements of this license.
292  
293 This license does not grant you the right to use any trademark, service mark,
294 tradename, or logo of the Copyright Holder.
295  
296 This license includes the non-exclusive, worldwide, free-of-charge patent license
297 to make, have made, use, offer to sell, sell, import and otherwise transfer the
298 Package with respect to any patent claims licensable by the Copyright Holder that
299 are necessarily infringed by the Package. If you institute patent litigation
300 (including a cross-claim or counterclaim) against any party alleging that the
301 Package constitutes direct or contributory patent infringement,then this Artistic
302 License to you shall terminate on the date that such litigation is filed.
303  
304 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
305 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
306 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
307 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
308 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
309 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
310 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
311  
312 =cut
313  
314 5 1; # End of Lingua::IND::Numbers
↑ Summary