phone_number¶ ↑
DESCRIPTION¶ ↑
Encapsulates the composed of pattern for phone numbers into any easy to use library.
FEATURES¶ ↑
-
Store a phone number unformatted in a single database field, but load it as a PhoneNumber::Number object.
-
Parse virtually any formatting a phone number can be represented with.
-
Format strings to contrl output.
-
Pre-defined named format strings to control output.
REQUIREMENTS¶ ↑
-
ActiveRecord >= 2.3
INSTALL¶ ↑
gem sources -a http://gemcutter.org sudo gem install phone_number
INSTALL FOR RAILS¶ ↑
Add to environment file:
config.gem "phone_number", :version => '0.0.1', :source => 'http://gemcutter.org'
Run:
sudo rake:gems:install
USAGE¶ ↑
Generate a migration to add the necessary field to the database:
script/generate phone_number_migration {file_name} {table_name} {field_name} script/generate phone_number_migration users_have_mobile_phone_numbers users homee_phone
Call the macro in an ActiveRecord descendant:
class User < ActiveRecord::Base phone_number :home_phone end
Set the field equal to something:
@user.phone_number = '+01 234-576-8901 x 123'
Use the field:
@user.to_s # (234) 576-8901
Use formats to control the output:
@user.to_s( '%a.%m.%p' ) # 234.576.8901
Use pre-defined named formats to control the output:
@user.to_s( :us ) # 01 (234) 567-8901 x 123
Reference the raw database field:
@user.raw_home_phone # 012345768901x123
Reference the sub parts of the field:
@user.home_phone.country_code # 01 @user.home_phone.area_code # 234 @user.home_phone.subscriber_number_prefix # 567 @user.home_phone.subscriber_number_postfix # 8901 @user.home_phone.extension # 123
Note on Patches/Pull Requests¶ ↑
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.
Copyright¶ ↑
Copyright © 2009 C. Jason Harrelson (midas)
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.