0.0
No release in over 3 years
Low commit activity in last 3 years
Validates Spanish landlines and mobile numbers. There are also methods to get province for landline numbers and type.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16
>= 11.2.2, ~> 11.2
~> 3.0
 Project Readme

Build Status

SpainPhone

A gem for validating Spanish telephone numbers. Check if a number is valid, type (fixed, landline) and get area code and provinces for landlines.

Installation

Add this line to your application's Gemfile:

gem 'spain_phone'

And then execute:

$ bundle

Or install it yourself as:

$ gem install spain_phone

Usage

Create a new SpainPhone::Phone object passing a the telephone number as a string in a single argument without the country code.

phone = SpainPhone::Phone.new('936546515')

phone.valid? => true

phone.phone_type => 'landline'

phone.province => :Barcelona

phone.area_code => '936'

phone.country_code => '+34'

phone.international => '+34936546515'

phone.phone_number => '936546515'

Random phone numbers can also be generated for each type using the Generator class. All the methods from SpainPhone::Phone are then available for each generated object.

SpainPhone::Generator.landline 
=> #<SpainPhone::Phone:0x00005636df2b4078 @phone_number="941804356">

SpainPhone::Generator.mobile 
=> #<SpainPhone::Phone:0x00005636df2c3690 @phone_number="727004177">

SpainPhone::Generator.premium 
=> #<SpainPhone::Phone:0x00005636df2ca8f0 @phone_number="902399160">

SpainPhone::Generator.toll_free 
=> <SpainPhone::Phone:0x00005636df2d4530 @phone_number="900968312">
Available phone types
  • landline
  • mobile
  • toll-free
  • premium

Development

After checking out the repo, run bin/setup to install dependencies. Then, run bundle exec rspec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/nevadajames/spain_phone.

License

The gem is available as open source under the terms of the MIT License.