Giter VIP home page Giter VIP logo

phone_number's Introduction

phone_number

github.com/midas/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 © 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.

phone_number's People

Stargazers

Duncan Miller avatar Robin Chou avatar Josh Rieken avatar Nate Klaiber avatar Billy Yarosh avatar Jason Harrelson avatar Minofare avatar Ryan Waldron avatar

Watchers

Minofare avatar Jason Harrelson avatar James Cloos avatar  avatar

Forkers

erebor shortcast

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.