Permalink
Browse files

Merge pull request #46 from yaoquan/master

Adds Singapore phone numbers
  • Loading branch information...
2 parents 01c89e1 + ec31238 commit e95a715e785a1d26e35cf7d37c3a7242472330e2 @EmmanuelOga EmmanuelOga committed Jul 3, 2012
Showing with 124 additions and 0 deletions.
  1. +1 −0 lib/ffaker.rb
  2. +81 −0 lib/ffaker/phone_number_sg.rb
  3. +42 −0 test/test_phone_number_sg.rb
View
@@ -50,6 +50,7 @@ def self.bothify(masks)
autoload :PhoneNumber, 'ffaker/phone_number'
autoload :PhoneNumberAU, 'ffaker/phone_number_au'
autoload :PhoneNumberSN, 'ffaker/phone_number_sn'
+ autoload :PhoneNumberSG, 'ffaker/phone_number_sg'
autoload :Product, 'ffaker/product'
autoload :VERSION, 'ffaker/version'
end
@@ -0,0 +1,81 @@
+# based on information from http://en.wikipedia.org/wiki/Telephone_numbers_in_Singapore
+module Faker
+ module PhoneNumberSG
+ extend ModuleUtils
+ extend self
+
+ # Number Ranges
+ # 3xxx xxxx - Voice Over IP services
+ # 6xxx xxxx - Fixed Line services inclusive of Fixed Line Voice Over IP services
+ # like StarHub Digital Voice and SingTel mio Voice
+ # 8xxx xxxx - Mobile phone services
+ # 9xxx xxxx - Mobile phone services Includes Paging Services like SUNPAGE
+ # 800 xxx xxxx - Toll-Free International services
+ # 1800 xxx xxxx - Toll-Free line services
+ # 1900 xxx xxxx - Premium Service
+
+ # Generates a voip phone number
+ # 3xxx xxxx
+ #
+ def voip_number
+ Faker.numerify("3### ####")
+ end
+
+ # Generates a fixed line phone number
+ # 6xxx xxxx
+ #
+ def fixed_line_number
+ Faker.numerify("6### ####")
+ end
+
+ # Generates a fixed mobile phone number
+ # 8xxx xxxx
+ #
+ def mobile_number
+ Faker.numerify("8### ####")
+ end
+
+ # Generates a fixed mobile phone number or pager service number
+ # 9xxx xxxx
+ #
+ def mobile_or_pager_number
+ Faker.numerify("9### ####")
+ end
+
+ # Generates an international toll-free number
+ # 800 xxx xxxx
+ #
+ def international_toll_free_number
+ Faker.numerify("800 ### ####")
+ end
+
+ # Generates an toll-free number
+ # 1800 xxx xxxx
+ #
+ def toll_free_number
+ Faker.numerify("1800 ### ####")
+ end
+
+ # Generates a premium service number
+ # (1900) xxx xxxx
+ #
+ def premium_service_number
+ Faker.numerify("1900 ### ####")
+ end
+
+
+ # generates mobile or home/work number
+ def phone_number
+ case rand(3)
+ when 0 then fixed_line_number
+ when 1 then mobile_number
+ when 2 then mobile_or_pager_number
+ end
+ end
+
+ def country_code
+ "+65"
+ end
+
+ end
+end
@@ -0,0 +1,42 @@
+require 'helper'
+
+class TestPhoneNumberSG < Test::Unit::TestCase
+ def setup
+ @tester = Faker::PhoneNumberSG
+ end
+
+ def test_voip_number
+ assert_match /3\d{3}\s\d{4}/, @tester.voip_number
+ end
+
+ def test_fixed_line_number
+ assert_match /6\d{3}\s\d{4}/, @tester.fixed_line_number
+ end
+
+ def test_mobile_number
+ assert_match /8\d{3}\s\d{4}/, @tester.mobile_number
+ end
+
+ def test_mobile_or_pager_number
+ assert_match /9\d{3}\s\d{4}/, @tester.mobile_or_pager_number
+ end
+
+ def test_international_toll_free_number
+ assert_match /800\s\d{3}\s\d{4}/, @tester.international_toll_free_number
+ end
+
+ def test_toll_free_number
+ assert_match /1800\s\d{3}\s\d{4}/, @tester.toll_free_number
+ end
+
+ def test_premium_service_number
+ assert_match /1900\s\d{3}\s\d{4}/, @tester.premium_service_number
+ end
+
+ def test_phone_number
+ 10.times do
+ assert_match /[6,8,9]\d{3}\s\d{4}/, @tester.phone_number
+ end
+ end
+end
+

0 comments on commit e95a715

Please sign in to comment.