No release in over a year
A simple class that generates a random valid unique phone number
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 4.2, >= 4.2.1
~> 0.6.45
 Project Readme

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.