README.md in phony_rails-0.8.1 vs README.md in phony_rails-0.8.2
- old
+ new
@@ -1,9 +1,7 @@
# PhonyRails
-(In its early days :) called PhonyNumber)
-
This small Gem adds useful methods to your Rails app to validate, display and save phone numbers.
It uses the super awesome Phony gem (https://github.com/floere/phony).
## Installation
@@ -21,10 +19,12 @@
## Usage
### Normalization / Model Usage
+#### ActiveRecord
+
For **ActiveRecord**, in your model add:
class SomeModel < ActiveRecord::Base
# Normalizes the attribute itself before validation
phony_normalize :phone_number, :default_country_code => 'US'
@@ -34,19 +34,23 @@
# Creates method normalized_fax_number that returns the normalized version of fax_number
phony_normalized_method :fax_number
end
+#### Mongoid
+
For **Mongoid**, in keeping with Mongoid plug-in conventions you must include the `Mongoid::Phony` module:
class SomeModel
include Mongoid::Document
include Mongoid::Phony
# methods are same as ActiveRecord usage
end
+#### General info
+
The `:default_country_code` options is used to specify a country_code when normalizing.
PhonyRails will also check your model for a country_code method to use when normalizing the number. So `'070-12341234'` with `country_code` 'NL' will get normalized to `'317012341234'`.
You can also do-it-yourself and call:
@@ -58,10 +62,12 @@
PhonyRails.normalize_number('some number', :country_code => 'NL')
PhonyRails.normalize_number('+4790909090', :country_code => 'SE') # => '464790909090' (forced to +46)
PhonyRails.normalize_number('+4790909090', :default_country_code => 'SE') # => '4790909090' (still +47 so not changed)
+The country_code should always be a ISO 3166-1 alpha-2 (http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).
+
### Validation
In your model use the Phony.plausible method to validate an attribute:
validates :phone_number, :phony_plausible => true
@@ -116,85 +122,28 @@
number = "010-12341234"
number.phony_formatted!(:normalize => :NL, :format => :international)
number # => "+31 10 123 41234"
+You can also easily normalize a phone number String:
+
+ "+31 (0)30 1234 123".phony_normalized # => '31301234123'
+ "(0)30 1234 123".phony_normalized # => '301234123'
+ "(0)30 1234 123".phony_normalized(country_code: 'NL') # => '301234123'
+
### Find by normalized number
Say you want to find a record by a phone number. Best is to normalize user input and compare to an attribute stored in the db.
Home.find_by_normalized_phone_number(PhonyRails.normalize_number(params[:phone_number]))
## Changelog
-0.7.0
-* Gem update.
-* Pinned Phony to v2.3.0.
-* Fixed regex.
+0.8.2
+* Added String#phony_normalized method
-0.6.0
-* Support for Phony 2.1 by @pjg.
-
-0.5.0
-* Added :strict option to String#phony_formatted.
-
-0.4.2
-* Added @fareastside validation for country_code.
-
-0.4.0/0.4.1
-* Better Mongoid support by @johnnyshields.
-
-0.3.0
-* Now ability to force change a country_code.
- See: https://github.com/joost/phony_rails/pull/23#issuecomment-17480463
-
-0.2.1
-* Better error handling by @k4nar.
-
-0.1.12
-* Further loosened gemspec dependencies.
-
-0.1.11
-* Better gemspec dependency versions by @rjhaveri.
-
-0.1.10
-* Changes from henning-koch.
-* Some pending fixes.
-
-0.1.8
-* Improved validation methods by @ddidier.
-
-0.1.6
-* Added :as option to phony_normalize.
-
-0.1.5
-* some tests and a helper method by @ddidier.
-
-0.1.2
-* Using countries gem as suggested by @brutuscat.
-* Fixes bugs mentioned by @ddidier.
-
-0.1.0
-* Added specs.
-
-0.0.10
-* Same fix as 0.0.9 but for phony_formatted method.
-
-0.0.9
-* Fix for using same options Hash for all models.
-
-0.0.8
-* Improved number cleaning not to remove '+' and leading 0's. Now works with national numbers starting with 0 followed by country_code. Eg. 032 in BE.
-
-0.0.7
-* Fixed problem with '+' number
-
-0.0.6
-* Fixed problem with '070-4157134' being parsed as US number
-
## TODO
-* Fix phony v2.x issues.
* Make this work: Home.find_by_normalized_phone_number(Home.normalize_number(params[:phone_number]))
So we use Home.normalize_number instead of PhonyRails.normalize_number. This way we can use the same default_country_code.
* Make country_code method configurable.
## Contributing