Skip to content
Browse files

+ added India

  • Loading branch information...
1 parent 9d1dd73 commit 668b155dc94b1226134f974d9910e997ac211f18 @jcfischer jcfischer committed with Dec 6, 2012
Showing with 67 additions and 1 deletion.
  1. +1 −1 README.textile
  2. +1 −0 lib/phony.rb
  3. +52 −0 lib/phony/countries/india.rb
  4. +13 −0 spec/lib/phony/countries_spec.rb
View
2 README.textile
@@ -13,7 +13,7 @@ This gem can normalize, format and split E164 numbers.
The (admittedly crazy) *goal* of this Gem is to be able to format/split all phone numbers in the world.
-Currently handles Abhas, Afghan, Algerian, Austrian, Australian, Belgian, Brazilian, Cambodian, Chilean, Chinese, Croatian, Cuban, Cypriot, Czech, Danish, Dutch, Egyptian, Estonian, French, German, Ghanan, Gibraltar, Greek, Haiti, Hong Kong, Hungarian, Italian, Iran, Irish, Kazakh, Lithuanian, Luxembourgian, Malaysian, Malta, Mexican, Monaco, Morocco, New Zealand, Nigerian, Norwegian, Peruvian, Polish, Romanian, Russian, Rwandan, Seychelles, Singapore, Slovakian, South African, South Korean, South Osetian, Spanish, Sri Lankan, Sudan, Swedish, Swiss, Thailand, Tunisian, Turkish, Liechtenstein, UK, US, Venezuelan, and Vietnamese numbers.
+Currently handles Abhas, Afghan, Algerian, Austrian, Australian, Belgian, Brazilian, Cambodian, Chilean, Chinese, Croatian, Cuban, Cypriot, Czech, Danish, Dutch, Egyptian, Estonian, French, German, Ghanan, Gibraltar, Greek, Haiti, Hong Kong, Hungarian, Indian, Italian, Iran, Irish, Kazakh, Lithuanian, Luxembourgian, Malaysian, Malta, Mexican, Monaco, Morocco, New Zealand, Nigerian, Norwegian, Peruvian, Polish, Romanian, Russian, Rwandan, Seychelles, Singapore, Slovakian, South African, South Korean, South Osetian, Spanish, Sri Lankan, Sudan, Swedish, Swiss, Thailand, Tunisian, Turkish, Liechtenstein, UK, US, Venezuelan, and Vietnamese numbers.
And to some extent, all others. Just try if it works for you.
View
1 lib/phony.rb
@@ -30,6 +30,7 @@
require File.expand_path '../phony/countries/brazil', __FILE__
require File.expand_path '../phony/countries/china', __FILE__
require File.expand_path '../phony/countries/germany', __FILE__
+require File.expand_path '../phony/countries/india', __FILE__
require File.expand_path '../phony/countries/ireland', __FILE__
require File.expand_path '../phony/countries/italy', __FILE__
require File.expand_path '../phony/countries/malaysia', __FILE__
View
52 lib/phony/countries/india.rb
@@ -0,0 +1,52 @@
+# Indian phone numbers.
+#
+# http://en.wikipedia.org/wiki/Telephone_numbers_in_India
+# http://en.wikipedia.org/wiki/Mobile_telephone_numbering_in_India
+#
+# http://www.dot.gov.in/numbering_plan/numberplanindex.htm
+# http://www.dot.gov.in/numbering_plan/nnp2003.pdf
+# http://www.dot.gov.in/numbering_plan/2012/msc_codes_28092012.pdf
+#
+#
+
+
+sdca_with_2_digits = %w{ 11 20 22 33 39 40 44 50 60 70 79 80 }
+
+sdca_with_3_digits = %w{
+ 120 121 122 124 129 130 131 132 135 141 144 145 151 154 160 161 164 171 172 175 177 180 181 183 184 186 191 194
+ 210 212 217 230 231 233 239 240 241 249 250 251 254 257 260 261 265 268 270 272 278 281 285 286 288 291 294
+ 326 341 342 343 353 354 360 361 364 369 370 373 374 376 381 385 389
+ 413 416 421 423 424 427 431 435 451 452 461 462 469 470 471 474 475 476 477 478 479 480 481 483 484 485 487 490 491 494 495 496 497
+ 512 515 532 535 542 548 551 562 565 572 581 595
+ 612 621 631 641 651 657 661 663 671 674 680
+ 712 721 724 731 733 734 744 751 755 761 747 788
+ 816 820 821 824 831 832 836 861 863 866 870 877 878 883 884 891
+
+
+ 140
+ 240 249 254 260 270 272
+ 300 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 318 320 327 328 329 340 344 349 350 357 388
+ 412 419 430 438 439 450 453 458 459 460 464 466 467 468
+ 510 513 520 523 529 530 537 538 539 540 543 547 550 553 557 558 559 560 563 570 575 576 577 578 579 580 589 590 593 597 598 599
+ 610 614 616 617 619 620 623 626 628 629 630 635 636 637 638 639 640 644 648 649 650 660 669 670 677 687 688 689
+ 730 735 738 740 750 787 789
+ 812 814 829 843 860 879 880 887 889 890 895 897 898 899
+
+}
+
+
+
+mobile = %w{ 91 92 93 94 97 98 99}
+
+pagers = %w{ 96 }
+
+Phony.define do
+ country '91', one_of(sdca_with_3_digits) >> split(3, 2, 2) |
+ one_of(sdca_with_2_digits) >> split(3, 2, 3) |
+ one_of(mobile) >> split(3, 2, 3) |
+ one_of(pagers) >> split(2, 3, 3) |
+
+ fixed(4) >> split(3, 3), # fallback (4 digit sdca)
+ validate_lengths(10)
+
+end
View
13 spec/lib/phony/countries_spec.rb
@@ -164,6 +164,14 @@ def self.it_splits number, expected
it_splits '62217815263', ['62', '21', '7815263']
end
+
+ describe 'India' do
+ it_splits '919911182111', ['91', '99', '111', '82', '111'] # mobile
+ it_splits '912212345678', ['91', '22', '123', '45', '678'] # New Delhi
+ it_splits '911411234567', ['91', '141', '123', '45', '67'] # Jaipur
+ it_splits '913525123456', ['91', '3525', '123', '456' ] # DALKHOLA
+ end
+
describe 'Iran' do
it_splits '982112341234', ['98', '21', '1234', '1234'] # Teheran
it_splits '989191231234', ['98', '919', '123', '1234'] # Example Cell Phone
@@ -304,6 +312,11 @@ def self.it_splits number, expected
it { Phony.split('421212345678').should == ['421', '2', '12345678'] } # Bratislava
it { Phony.split('421371234567').should == ['421', '37', '1234567'] } # Nitra / Other
end
+
+ describe 'Sri Lanka' do
+ it { Phony.split('94711231212').should == ['94', '71', '123', '12', '12'] } # Mobile
+ end
+
describe 'Sweden' do
it { Phony.split('46812345678').should == ['46', '8', '12345678'] } # Stockholm
it { Phony.split('46111234567').should == ['46', '11', '1234567'] }

0 comments on commit 668b155

Please sign in to comment.
Something went wrong with that request. Please try again.