README.md in torasup-0.0.9 vs README.md in torasup-0.0.10

- old
+ new

@@ -1,10 +1,10 @@ # Torasup Retuns metadata about a phone number such as operator info, area code and more. -[![Build Status](https://travis-ci.org/dwilkie/torasup.png)](https://travis-ci.org/dwilkie/torasup) [![Dependency Status](https://gemnasium.com/dwilkie/torasup.png)](https://gemnasium.com/dwilkie/torasup) [![Coverage Status](https://coveralls.io/repos/dwilkie/torasup/badge.png)](https://coveralls.io/r/dwilkie/torasup) [![Code Climate](https://codeclimate.com/github/dwilkie/torasup.png)](https://codeclimate.com/github/dwilkie/torasup) +[![Build Status](https://travis-ci.org/dwilkie/torasup.png)](https://travis-ci.org/dwilkie/torasup) [![Dependency Status](https://gemnasium.com/dwilkie/torasup.png)](https://gemnasium.com/dwilkie/torasup) [![Code Climate](https://codeclimate.com/github/dwilkie/torasup.png)](https://codeclimate.com/github/dwilkie/torasup) ## Installation Add this line to your application's Gemfile: @@ -12,32 +12,32 @@ gem 'torasup' ``` And then execute: -```shell +``` $ bundle ``` Or install it yourself as: -```shell +``` $ gem install torasup ``` ## Usage -### Examples +### Returning info about a Phone Number -```shell +``` $ irb ``` ```ruby require 'torasup' -pn = Torasup::PhoneNumber.new("+855 (0) 62 451 234") +pn = Torasup::PhoneNumber.new("+855 (0) 62 451 2345") pn.number => "85562451234" pn.country_code @@ -51,11 +51,11 @@ pn.prefix => "45" pn.local_number -=> "1234" +=> "12345" loc = pn.location loc.area => "Kampong Thom" @@ -66,10 +66,24 @@ op.name => "Smart" ``` +### Accessing Metadata by Operator + +```ruby +Torasup::Operator.all["kh"]["metfone"]["mobile_prefixes"] +=> {"85538"=>{"subscriber_number_min"=>2000000, "subscriber_number_max"=>9999999, "subscriber_number_pattern"=>"[2-9]\\d{6}"}} +``` + +### Accessing Metadata by Prefix + +```ruby +Torasup.prefixes["8552345"] +=> {"country_id"=>"kh", "id"=>"smart", "name"=>"Smart", "subscriber_number_min"=>0, "subscriber_number_max"=>99999, "subscriber_number_pattern"=>"\\d{5}", "type"=>"landline", "prefix"=>"45", "area_code"=>"23"} +``` + ## Configuration ### Overriding Data Sometimes it maybe necessary to override the data that Torasup provides. For example you may want to provide custom attributes for different operators. In order to achieve this you can provide a custom [psdn](http://en.wikipedia.org/wiki/Public_switched_telephone_network) data file. Custom files also support interpolations using the `%{interpolation}` [I18n syntax](http://guides.rubyonrails.org/i18n.html#interpolation). See the format of sample custom [pstn data file](https://github.com/dwilkie/torasup/blob/master/spec/support/custom_pstn.yaml) for more info. e.g. @@ -99,11 +113,11 @@ ```ruby Torasup.configure do |config| config.custom_pstn_data_file = "my_pstn_data.yaml" end -pn = Torasup::PhoneNumber.new("+855 (0) 62 451 234") +pn = Torasup::PhoneNumber.new("+855 (0) 62 451 2345") op = pn.operator op.id => "hello" @@ -118,27 +132,21 @@ op.my_custom_boolean_property => true ``` -### Accessing Operator Metadata - -```ruby -Torasup::Operator.all["kh"]["metfone"]["prefixes"] -=> ["85597", "85588"] -``` - ### Registering Operators Sometimes you may only be interested in certain prefixes. For example let's say you want to match phone numbers from a certain operator from the database. You can register operators for this purpose. e.g. ```ruby Torasup.configure do |config| - config.register_operators("kh", "metfone") + config.register_operators("kh", "cootel") end Torasup::Operator.registered -=> {"kh"=>{"metfone"=>{"country_id"=>"kh", "id"=>"metfone", "name"=>"Metfone", "prefixes"=>["85597", "85588"]}}} +=> {"kh"=>{"cootel"=>{"country_id"=>"kh", "id"=>"cootel", "name"=>"CooTel", "mobile_prefixes"=>{"85538"=>{"subscriber_number_min"=>2000000, "subscriber_number_max"=>9999999, "subscriber_number_pattern"=>"[2-9]\\d{6}"}} +}}} ``` ### Default Operators By default the following counties will take precedence: `["US", "GB", "AU", "IT", "RU", "NO"]`. To override use the following configuration setting: