Coder Social home page Coder Social logo

has_phone_numbers's Introduction

has_phone_numbers

has_phone_numbers demonstrates a reference implementation for handling phone numbers.

Resources

API

Bugs

Development

Testing

Source

  • git://github.com/pluginaweek/has_phone_numbers.git

Mailing List

Description

A phone number is a simple model whose data and functionality should be standardized across multiple applications. Phone numbers are minimalistic in terms of the type of data it represents. Both U.S. and international formats are supported.

Usage

Note that this is a reference implementation and, most likely, will be modified for your own usage.

Installation

has_phone_numbers requires an additional database table to work. You can generate a migration for this tables like so:

script/generate has_phone_numbers

Then simply migrate your database:

rake db:migrate

Example

Building with individual segments:

PhoneNumber.create(:phoneable => user, :country_code => '1', :number => '1234567890', :extension => '123')
# #<PhoneNumber id: 1, phoneable_id: 1, phoneable_type: "User", country_code: "1", number: "1234567890", extension: "123", created_at: "2009-01-01 00:00:00", updated_at: "2009-01-01 00:00:00">

Parsing raw values:

PhoneNumber.create(:phoneable => user, :content => '1 1234567890 ext. 123')
# #<PhoneNumber id: 1, phoneable_id: 1, phoneable_type: "User", country_code: "1", number: "1234567890", extension: "123", created_at: "2009-01-01 00:00:00", updated_at: "2009-01-01 00:00:00">

PhoneNumber.create(:phoneable => user, :content => '231 331 996 x4621')
# #<PhoneNumber id: 1, phoneable_id: 1, phoneable_type: "User", country_code: "231", number: "331996", extension: "4621", created_at: "2009-01-01 00:00:00", updated_at: "2009-01-01 00:00:00">

PhoneNumber.create(:phoneable => user, :content => '+ 386 1 5853 449')
# #<PhoneNumber id: 1, phoneable_id: 1, phoneable_type: "User", country_code: "386", number: "15853449", extension: nil, created_at: "2009-01-01 00:00:00", updated_at: "2009-01-01 00:00:00">

PhoneNumber.create(:phoneable => user, :content => '+39-02-4823001')
# #<PhoneNumber id: 1, phoneable_id: 1, phoneable_type: "User", country_code: "39", number: "024823001", extension: nil, created_at: "2009-01-01 00:00:00", updated_at: "2009-01-01 00:00:00">

Testing

Before you can run any tests, the following gem must be installed:

To run against a specific version of Rails:

rake test RAILS_FRAMEWORK_ROOT=/path/to/rails

Dependencies

  • Rails 2.3 or later

References

has_phone_numbers's People

Contributors

mlightner avatar obrie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.