README.md in phony_rails-0.1.6 vs README.md in phony_rails-0.1.7
- old
+ new
@@ -19,10 +19,12 @@
$ gem install phony_rails
## Usage
+### Normalization / ActiveRecord Extension
+
In your model add:
class SomeModel < ActiveRecord::Base
# Normalizes the attribute itself before
@@ -37,18 +39,43 @@
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'`.
-Use the Phony.plausible method to validate an attribute:
+### Validation
+In your model use the Phony.plausible method to validate an attribute:
+
validates :phone_number, :phony_plausible => true
+or the helper method:
+
+ validates_plausible_phone :phone_number
+
+this method use other validators under the hood to provide:
+* presence validation using `ActiveModel::Validations::PresenceValidator`
+* format validation using `ActiveModel::Validations::FormatValidator`
+
+so we can use:
+
+ validates_plausible_phone :phone_number, :presence => true
+ validates_plausible_phone :phone_number, :with => /^\+\d+/
+ validates_plausible_phone :phone_number, :without => /^\+\d+/
+ validates_plausible_phone :phone_number, :presence => true, :with => /^\+\d+/
+
+### Display / Views
+
In your views use:
<%= "some number string variable".phony_formatted(:format => :international, :spaces => '-') %>
+### 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.1.6
* Added :as option to phony_normalize.
@@ -74,9 +101,15 @@
0.0.7
* Fixed problem with '+' number
0.0.6
* Fixed problem with '070-4157134' being parsed as US number
+
+## TODO
+
+* 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
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)