Skip to content

Latest commit

 

History

History
50 lines (34 loc) · 1.48 KB

README.md

File metadata and controls

50 lines (34 loc) · 1.48 KB

Generate random, unique, valid phone numbers in e164 format.

Gem Version

Motive

While i was using the faker-ruby gem. I noticed numbers generated via the Faker::PhoneNumber class where not valid phone numbers, when i ran it against Phonelib.valid? the results were always false.

I got inspired to make this little gem to help me generate random numbers for testing data.

Installation

Add the following line to your Gemfile

group :test do
  gem 'fake_phone_number_generator', '~> 1.0'
end

Or Install directly via Rubygems

gem install fake_phone_number_generator

How this library works

The lib generates a random number, it saves a list of all generated numbers so that it can generate a unique each time it is called to avoid unique database constraints errors. The generated numbers can be accessed via

 FakePhoneNumberGenerator.generated_numbers

Generating a new number

To generate a new number, simply call .generate and pass the country named argument.

FakePhoneNumberGenerator.generate country: "US"
# => "125577492939"

FakePhoneNumberGenerator.generate country: "IQ"
# => "964958765359"

FakePhoneNumberGenerator.generate country: "FR"
# => "337377555666"

The country can be any valid ISO alpha-2 format. That is the country name abbreviated in two letters.