torasup 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2bcfb1ffbd42ca86f97773f2febf32f945141f60
4
- data.tar.gz: 9c421d8d53db393fd4987159895616d4607e5ba0
3
+ metadata.gz: 283b66841ac0eefc8722548fe2cc907420f2dd0c
4
+ data.tar.gz: b93ad11ac2091509281fc4fb67d3ed9980401c3d
5
5
  SHA512:
6
- metadata.gz: f748990a8e8bd46ba202d18d6c833fc53cf9ba4cfaa34f252b1b89a9b056db57efed8fc6b063d7a99b1d7564808da9d3de9b1c7fd3d61b780f2aeb16a610c2ac
7
- data.tar.gz: 34119686c1361a051652d5a532f0ad3876a882fd19608f621451820f35129c0663b50659c2ba1bafdd8eb975b924fea2ba94c85b1fac7bd8c303dee7bdfe7b38
6
+ metadata.gz: 41cbf042bcaf42cca4deb73a439d078edbf46a4b2cc9563f5ad51ff28b59ef4a220e438a52ecf9df6374d3dab2e8332f90d1e1113234c9c6ff2f6d5eba7bcf4b
7
+ data.tar.gz: 5c656d780cfde1a4bd2bf4c831cd15010ac19b8ba521ee335f8a9704b33f9acbdf4d2ec930e984d34a864baa886e0d084f6acef74f9bc029fbf881c33ff72929
data/README.md CHANGED
@@ -2,60 +2,71 @@
2
2
 
3
3
  Retuns metadata about a phone number such as operator info, area code and more.
4
4
 
5
- [![Build Status](https://travis-ci.org/dwilkie/torasup.png)](https://travis-ci.org/dwilkie/torasup)
5
+ [![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)
6
6
 
7
7
  ## Installation
8
8
 
9
9
  Add this line to your application's Gemfile:
10
10
 
11
- gem 'torasup'
11
+ ```ruby
12
+ gem 'torasup'
13
+ ```
12
14
 
13
15
  And then execute:
14
16
 
15
- $ bundle
17
+ ```shell
18
+ $ bundle
19
+ ```
16
20
 
17
21
  Or install it yourself as:
18
22
 
19
- $ gem install torasup
23
+ ```shell
24
+ $ gem install torasup
25
+ ```
20
26
 
21
27
  ## Usage
22
28
 
23
29
  ### Examples
24
30
 
25
- $ irb
31
+ ```shell
32
+ $ irb
33
+ ```
26
34
 
27
- > require 'torasup'
28
- > pn = Torasup::PhoneNumber.new("+855 (0) 62 451 234")
35
+ ```ruby
36
+ require 'torasup'
29
37
 
30
- > pn.number
31
- => "85562451234"
38
+ pn = Torasup::PhoneNumber.new("+855 (0) 62 451 234")
32
39
 
33
- > pn.country_code
34
- => "855"
40
+ pn.number
41
+ => "85562451234"
35
42
 
36
- > pn.country_id
37
- => "kh"
43
+ pn.country_code
44
+ => "855"
38
45
 
39
- > pn.area_code
40
- => "62"
46
+ pn.country_id
47
+ => "kh"
41
48
 
42
- > pn.prefix
43
- => "45"
49
+ pn.area_code
50
+ => "62"
44
51
 
45
- > pn.local_number
46
- => "1234"
52
+ pn.prefix
53
+ => "45"
47
54
 
48
- > loc = pn.location
49
- > loc.area
50
- => "Kampong Thom"
55
+ pn.local_number
56
+ => "1234"
51
57
 
52
- > op = pn.operator
58
+ loc = pn.location
59
+ loc.area
60
+ => "Kampong Thom"
53
61
 
54
- > op.id
55
- => "smart"
62
+ op = pn.operator
56
63
 
57
- > op.name
58
- => "Smart"
64
+ op.id
65
+ => "smart"
66
+
67
+ op.name
68
+ => "Smart"
69
+ ```
59
70
 
60
71
  ## Configuration
61
72
 
@@ -63,72 +74,83 @@ Or install it yourself as:
63
74
 
64
75
  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.
65
76
 
66
- # my_pstn_data.yaml
67
- ---
68
- kh:
69
- area_codes:
70
- "45": "New Province"
71
- operators:
72
- hello:
73
- metadata:
74
- name: Hello
75
- my_custom_property: hello-foo
76
- my_custom_interpolated_property: "hello-%{interpolation}"
77
- prefixes:
78
- - '15'
79
- - '16'
80
- - '81'
81
- - '87'
82
- area_code_prefixes:
83
- - '45'
84
-
85
- > Torasup.configure do |config|
86
- > custom_pstn_data_file = "my_pstn_data.yaml"
87
- > end
88
-
89
- > pn = Torasup::PhoneNumber.new("+855 (0) 62 451 234")
90
- > op = pn.operator
91
-
92
- > op.id
93
- => "hello"
94
-
95
- > op.name
96
- => "Hello"
97
-
98
- > op.my_custom_property
99
- => "hello-foo"
100
-
101
- > op.my_custom_interpolated_property(:interpolation => "bar")
102
- => "hello-bar"
77
+ ```yaml
78
+ # my_pstn_data.yaml
79
+ ---
80
+ kh:
81
+ area_codes:
82
+ "45": "New Province"
83
+ operators:
84
+ hello:
85
+ metadata:
86
+ name: Hello
87
+ my_custom_property: hello-foo
88
+ my_custom_interpolated_property: "hello-%{interpolation}"
89
+ prefixes:
90
+ - '15'
91
+ - '16'
92
+ - '81'
93
+ - '87'
94
+ area_code_prefixes:
95
+ - '45'
96
+ ```
97
+
98
+ ```ruby
99
+ Torasup.configure do |config|
100
+ config.custom_pstn_data_file = "my_pstn_data.yaml"
101
+ end
102
+
103
+ pn = Torasup::PhoneNumber.new("+855 (0) 62 451 234")
104
+ op = pn.operator
105
+
106
+ op.id
107
+ => "hello"
108
+
109
+ op.name
110
+ => "Hello"
111
+
112
+ op.my_custom_property
113
+ => "hello-foo"
114
+
115
+ op.my_custom_interpolated_property(:interpolation => "bar")
116
+ => "hello-bar"
117
+ ```
103
118
 
104
119
  ### Accessing Operator Metadata
105
120
 
106
- > Torasup::Operator.all["kh"]["metfone"]["prefixes"]
107
- => ["85597", "85588"]
121
+ ```ruby
122
+ Torasup::Operator.all["kh"]["metfone"]["prefixes"]
123
+ => ["85597", "85588"]
124
+ ```
108
125
 
109
126
  ### Registering Operators
110
127
 
111
128
  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.
112
129
 
113
- > Torasup.configure do |config|
114
- > register_operators("kh", "metfone")
115
- > end
116
-
117
- > Torasup::Operator.registered
118
- => {"kh"=>["metfone"]}
130
+ ```ruby
131
+ Torasup.configure do |config|
132
+ config.register_operators("kh", "metfone")
133
+ end
119
134
 
120
- > Torasup::Operator.registered_prefixes
121
- => ["85597", "85588"]
135
+ Torasup::Operator.registered
136
+ => {"kh"=>{"metfone"=>{"country_id"=>"kh", "id"=>"metfone", "name"=>"Metfone", "prefixes"=>["85597", "85588"]}}}
137
+ ```
122
138
 
123
139
  ### Default Operators
124
140
 
125
- By default the following counties will take precedence: `["US", "GB", "AU", "IT", "RU", "NO"]`. This means that `Torasup::PhoneNumber.new(+1 415-234 567).country_id` will return `"us"` and not `ca`. To override use the following configuration setting.
141
+ By default the following counties will take precedence: `["US", "GB", "AU", "IT", "RU", "NO"]`. To override use the following configuration setting:
142
+
143
+ ```ruby
144
+ Torasup::PhoneNumber.new("+1 415-234 567").country_id
145
+ => "us"
126
146
 
127
- > Torasup.configure do |config|
128
- > config.default_countries = ["CA"]
129
- > end
147
+ Torasup.configure do |config|
148
+ config.default_countries = ["CA"]
149
+ end
130
150
 
131
- Now `Torasup::PhoneNumber.new(+1 415-234 567).country_id` will return `"ca"`
151
+ Torasup::PhoneNumber.new("+1 415-234 567").country_id
152
+ => "ca"
153
+ ```
132
154
 
133
155
  ## Testing
134
156
 
@@ -136,37 +158,39 @@ Torasup exposes a few test helpers methods which you can use in your tests. See
136
158
 
137
159
  Here's an example using rspec:
138
160
 
139
- require 'spec_helper'
161
+ ```ruby
162
+ require 'spec_helper'
140
163
 
141
- describe User do
142
- include Torasup::Test::Helpers
164
+ describe User do
165
+ include Torasup::Test::Helpers
143
166
 
144
- ASSERTED_REGISTERED_OPERATORS = {"kh" => %w{smart beeline hello}}
167
+ ASSERTED_REGISTERED_OPERATORS = {"kh" => %w{smart beeline hello}}
145
168
 
146
- # override this method to return the full path of the yaml spec
147
- def yaml_file(filename)
148
- File.join(File.dirname(__FILE__), "/#{filename}")
149
- end
169
+ # override this method to return the full path of the yaml spec
170
+ def yaml_file(filename)
171
+ File.join(File.dirname(__FILE__), "/#{filename}")
172
+ end
150
173
 
151
- # provide a custom spec file for example see:
152
- # see https://github.com/dwilkie/torasup/blob/master/spec/support/custom_pstn_spec.yaml
153
- def pstn_data(custom_spec = nil)
154
- super("custom_operators_spec.yaml")
155
- end
174
+ # provide a custom spec file for example see:
175
+ # see https://github.com/dwilkie/torasup/blob/master/spec/support/custom_pstn_spec.yaml
176
+ def pstn_data(custom_spec = nil)
177
+ super("custom_operators_spec.yaml")
178
+ end
156
179
 
157
- def with_operators(&block)
158
- super(:only_registered => ASSERTED_REGISTERED_OPERATORS, &block)
159
- end
180
+ def with_operators(&block)
181
+ super(:only_registered => ASSERTED_REGISTERED_OPERATORS, &block)
182
+ end
160
183
 
161
- describe "#operator" do
162
- it "should return the correct operator" do
163
- with_operators do |number_parts, assertions|
164
- new_user = build(:user, :phone_number => number_parts.join)
165
- new_user.operator.should == assertions["name"]
166
- end
167
- end
184
+ describe "#operator" do
185
+ it "should return the correct operator" do
186
+ with_operators do |number_parts, assertions|
187
+ new_user = build(:user, :phone_number => number_parts.join)
188
+ new_user.operator.should == assertions["name"]
168
189
  end
169
190
  end
191
+ end
192
+ end
193
+ ```
170
194
 
171
195
  In this example `with_operators` is used to yield a to block with a sample number (yielded as `number_parts`) and a hash of assertions (yielded as `assertions`) made about that number. The assertions are defined in `custom_operators_spec.yaml` which is in the same directory as this spec file.
172
196
 
@@ -18,26 +18,12 @@ module Torasup
18
18
  end
19
19
  end
20
20
 
21
- def self.registered_prefixes
22
- Torasup.registered_prefixes
23
- end
24
-
25
21
  def self.registered
26
- Torasup.registered_operators
22
+ build_metadata(:registered_operator_prefixes)
27
23
  end
28
24
 
29
25
  def self.all
30
- operators = {}
31
- Torasup.prefixes.each do |prefix, metadata|
32
- prefix_country_id = metadata["country_id"]
33
- country_operators = operators[prefix_country_id] ||= {}
34
- prefix_operator_id = metadata["id"]
35
- operator_metadata = country_operators[prefix_operator_id] ||= metadata.dup
36
- operator_metadata.delete("prefix")
37
- prefixes = operator_metadata["prefixes"] ||= []
38
- prefixes << prefix
39
- end
40
- operators
26
+ build_metadata(:prefixes)
41
27
  end
42
28
 
43
29
  private
@@ -63,5 +49,21 @@ module Torasup
63
49
  parts = [@area_code, @prefix] if parts.empty?
64
50
  @country_code + parts.join
65
51
  end
52
+
53
+ def self.build_metadata(operator_type)
54
+ operators = {}
55
+ Torasup.send(operator_type).each do |prefix, metadata|
56
+ prefix_country_id = metadata["country_id"]
57
+ country_operators = operators[prefix_country_id] ||= {}
58
+ prefix_operator_id = metadata["id"]
59
+ operator_metadata = country_operators[prefix_operator_id] ||= metadata.dup
60
+ operator_metadata.delete("prefix")
61
+ prefixes = operator_metadata["prefixes"] ||= []
62
+ prefixes << prefix
63
+ end
64
+ operators
65
+ end
66
+
67
+ private_class_method :build_metadata
66
68
  end
67
69
  end
@@ -1,8 +1,34 @@
1
1
  module Torasup
2
2
  module Test
3
3
  module Helpers
4
+
5
+ RSpec.configure do |config|
6
+ config.before do
7
+ clear_pstn
8
+ clear_registered_operators
9
+ end
10
+ end
11
+
4
12
  private
5
13
 
14
+ def clear_pstn
15
+ Torasup.configure do |config|
16
+ config.custom_pstn_data_file = nil
17
+ end
18
+ end
19
+
20
+ def clear_registered_operators
21
+ Torasup.configure do |config|
22
+ config.registered_operators = {}
23
+ end
24
+ end
25
+
26
+ def configure_registered_operators(country_id, *operators)
27
+ Torasup.configure do |config|
28
+ config.register_operators(country_id, *operators)
29
+ end
30
+ end
31
+
6
32
  def yaml_file(filename)
7
33
  raise "Override this method to return the full path of the yaml spec"
8
34
  end
@@ -16,14 +42,13 @@ module Torasup
16
42
  end
17
43
 
18
44
  def pstn_data(custom_spec = nil)
19
- return @pstn_data if @pstn_data
20
45
  if custom_spec == true
21
46
  custom_spec = pstn_spec("custom_pstn_spec.yaml")
22
47
  elsif custom_spec
23
48
  custom_spec = yaml_file(custom_spec)
24
49
  end
25
50
  data = load_yaml_file(pstn_spec("pstn_spec.yaml"))
26
- @pstn_data = custom_spec ? data.deeper_merge(load_yaml_file(custom_spec)) : data
51
+ custom_spec ? data.deeper_merge(load_yaml_file(custom_spec)) : data
27
52
  end
28
53
 
29
54
  def with_operators(options = {}, &block)
@@ -1,3 +1,3 @@
1
1
  module Torasup
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/torasup.rb CHANGED
@@ -47,18 +47,14 @@ module Torasup
47
47
  @pstn_prefixes[prefix] || {}
48
48
  end
49
49
 
50
- def registered_prefixes
51
- @registered_pstn_prefixes.keys
50
+ def registered_operator_prefixes
51
+ @registered_pstn_prefixes.dup
52
52
  end
53
53
 
54
54
  def prefixes
55
55
  @pstn_prefixes.dup
56
56
  end
57
57
 
58
- def registered_operators
59
- configuration.registered_operators.dup
60
- end
61
-
62
58
  private
63
59
 
64
60
  def load_pstn_prefixes!
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'torasup'
2
+ require 'coveralls'
3
+ Coveralls.wear!
2
4
 
3
5
  RSpec.configure do |config|
4
6
  Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
@@ -3,84 +3,13 @@ module PstnHelpers
3
3
 
4
4
  private
5
5
 
6
- def clear_pstn_data
7
- @pstn_data = nil
8
- end
9
-
10
6
  def yaml_file(filename)
11
7
  File.join(File.dirname(__FILE__), "../../spec/support/#{filename}")
12
8
  end
13
9
 
14
- def with_phone_numbers(options = {}, &block)
15
- phone_number_assertions = {}
16
- with_pstn_data(options) do |country_id, country_data, country_prefix|
17
- area_code_or_prefix = (10 + rand(100 - 10)).to_s
18
- local_number = [(100 + rand(1000 - 100)).to_s, (100 + rand(1000 - 100)).to_s]
19
- sample_number = "+#{country_prefix} (0) #{area_code_or_prefix}-#{local_number[0]}-#{local_number[1]}"
20
- normalized_number = country_prefix + area_code_or_prefix + local_number[0] + local_number[1]
21
- phone_number_assertions[sample_number] = {
22
- "number" => normalized_number, "country_id" => country_id, "country_code" => country_prefix,
23
- "area_code_or_prefix" => area_code_or_prefix, "local_number" => local_number.join
24
- }
25
- end
26
- phone_number_assertions.each do |sample_number, assertions|
27
- yield sample_number, assertions
28
- end
29
- end
30
-
31
- def with_locations(options = {}, &block)
32
- location_assertions = {}
33
- with_pstn_data(options) do |country_id, country_data|
34
- default_assertions = {"country_id" => country_id}
35
- location_assertions[country_id] = {}
36
- country_data["area_codes"].each do |area_code, area|
37
- location_assertions[country_id][area_code] = default_assertions.merge("area_code" => area_code, "area" => area)
38
- end
39
- end
40
- location_assertions.each do |country_id, area_code_assertions|
41
- area_code_assertions.each do |area_code, assertions|
42
- yield country_id, area_code, assertions
43
- end
44
- end
45
- end
46
-
47
- def sample_operator
48
- country = pstn_data.first
49
- [country.first, country.last["operators"].first.first]
50
- end
51
-
52
- def prefixes(country_id, *operators)
53
- prefix_data = []
54
- country_data = pstn_data[country_id]
55
- country_prefix = country_data["prefix"]
56
- operators.each do |operator|
57
- operator_data = country_data["operators"][operator]
58
- with_operator_area_codes(country_data, operator_data) do |area_code_prefix, area_code|
59
- prefix_data << (country_prefix + area_code + area_code_prefix)
60
- end
61
- with_operator_prefixes(operator_data) do |prefix|
62
- prefix_data << (country_prefix + prefix)
63
- end
64
- end
65
- prefix_data
66
- end
67
-
68
- def configure_with_custom_data(custom_data = true)
69
- custom_data_file = File.join(File.dirname(__FILE__), "../support", "/custom_pstn.yaml") if custom_data
70
- Torasup.configure do |config|
71
- config.custom_pstn_data_file = custom_data_file
72
- end
73
- end
74
-
75
- def configure_registered_operators(country_id, *operators)
76
- Torasup.configure do |config|
77
- config.register_operators(country_id, *operators)
78
- end
79
- end
80
-
81
- def clear_registered_operators
10
+ def configure_with_custom_data
82
11
  Torasup.configure do |config|
83
- config.registered_operators = {}
12
+ config.custom_pstn_data_file = File.join(File.dirname(__FILE__), "../support", "/custom_pstn.yaml")
84
13
  end
85
14
  end
86
15
  end
@@ -1,6 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Torasup do
4
+ include PstnHelpers
5
+
4
6
  describe ".configure" do
5
7
  describe "#registered_operators=" do
6
8
  before do
@@ -4,6 +4,22 @@ module Torasup
4
4
  describe Location do
5
5
  include PstnHelpers
6
6
 
7
+ def with_locations(options = {}, &block)
8
+ location_assertions = {}
9
+ with_pstn_data(options) do |country_id, country_data|
10
+ default_assertions = {"country_id" => country_id}
11
+ location_assertions[country_id] = {}
12
+ country_data["area_codes"].each do |area_code, area|
13
+ location_assertions[country_id][area_code] = default_assertions.merge("area_code" => area_code, "area" => area)
14
+ end
15
+ end
16
+ location_assertions.each do |country_id, area_code_assertions|
17
+ area_code_assertions.each do |area_code, assertions|
18
+ yield country_id, area_code, assertions
19
+ end
20
+ end
21
+ end
22
+
7
23
  shared_examples_for "a location" do
8
24
  it "should return all the location attributes" do
9
25
  with_locations(options) do |country_id, area_code, assertions|
@@ -18,10 +34,6 @@ module Torasup
18
34
  end
19
35
 
20
36
  context "using the standard data" do
21
- before do
22
- configure_with_custom_data(false)
23
- end
24
-
25
37
  it_should_behave_like "a location" do
26
38
  let(:options) { {} }
27
39
  end
@@ -4,66 +4,55 @@ module Torasup
4
4
  describe Operator do
5
5
  include PstnHelpers
6
6
 
7
- let(:operator) { sample_operator }
8
-
9
- describe ".registered" do
10
- context "given no operators have been registered" do
11
- before do
12
- clear_registered_operators
13
- end
7
+ let(:sample_operator) do
8
+ country = pstn_data.first
9
+ [country.first, country.last["operators"].first.first]
10
+ end
14
11
 
15
- it "should return an empty hash" do
16
- Operator.registered.should == {}
12
+ shared_examples_for "operator metadata" do
13
+ it "should return the operators with their metadata" do
14
+ operators = Operator.send(method)
15
+ operators = Operator.send(method) # run it twice to highlight the duplication problem
16
+ with_operators do |number_parts, assertions|
17
+ operator = operators[assertions["country_id"]][assertions["id"]]
18
+ operator["country_id"].should == assertions["country_id"]
19
+ operator["id"].should == assertions["id"]
20
+ operator["prefixes"].should == operator["prefixes"].uniq
21
+ operator["prefixes"].should include(
22
+ assertions["country_code"].to_s + assertions["area_code"].to_s + assertions["prefix"].to_s
23
+ )
17
24
  end
18
25
  end
26
+ end
19
27
 
20
- context "given one operator has been registered" do
21
- before do
22
- configure_registered_operators(operator[0], operator[1])
23
- configure_with_custom_data(false)
24
- end
25
-
26
- it "should return a hash of countries with registerd operators" do
27
- Operator.registered.should == {operator[0] => [operator[1]]}
28
- end
28
+ describe ".all" do
29
+ it_should_behave_like "operator metadata" do
30
+ let(:method) { :all }
29
31
  end
30
32
  end
31
33
 
32
- describe ".registered_prefixes" do
34
+ describe ".registered" do
33
35
  context "given no operators have been registered" do
34
36
  before do
35
37
  clear_registered_operators
36
38
  end
37
39
 
38
- it "should return an empty array" do
39
- Operator.registered_prefixes.should == []
40
+ it "should return an empty hash" do
41
+ Operator.registered.should == {}
40
42
  end
41
43
  end
42
44
 
43
45
  context "given one operator has been registered" do
44
46
  before do
45
- configure_registered_operators(operator[0], operator[1])
46
- configure_with_custom_data(false)
47
+ configure_registered_operators(sample_operator[0], sample_operator[1])
47
48
  end
48
49
 
49
- it "should return the prefixes for that operator" do
50
- Operator.registered_prefixes.should =~ prefixes(operator[0], operator[1])
51
- end
52
- end
53
- end
50
+ it_should_behave_like "operator metadata" do
51
+ let(:method) { :registered }
54
52
 
55
- describe ".all" do
56
- it "should return all the operators with their metadata" do
57
- operators = Operator.all
58
- operators = Operator.all # run it twice to highlight the duplication problem
59
- with_operators do |number_parts, assertions|
60
- operator = operators[assertions["country_id"]][assertions["id"]]
61
- operator["country_id"].should == assertions["country_id"]
62
- operator["id"].should == assertions["id"]
63
- operator["prefixes"].should == operator["prefixes"].uniq
64
- operator["prefixes"].should include(
65
- assertions["country_code"].to_s + assertions["area_code"].to_s + assertions["prefix"].to_s
66
- )
53
+ def with_operators(&block)
54
+ super(:only_registered => {sample_operator[0] => [sample_operator[1]]}, &block)
55
+ end
67
56
  end
68
57
  end
69
58
  end
@@ -84,10 +73,6 @@ module Torasup
84
73
  end
85
74
 
86
75
  context "using the standard data" do
87
- before do
88
- configure_with_custom_data(false)
89
- end
90
-
91
76
  it_should_behave_like "an operator" do
92
77
  let(:options) { {} }
93
78
  end
@@ -4,6 +4,24 @@ module Torasup
4
4
  describe PhoneNumber do
5
5
  include PstnHelpers
6
6
 
7
+ def with_phone_numbers(options = {}, &block)
8
+ phone_number_assertions = {}
9
+ with_pstn_data(options) do |country_id, country_data, country_prefix|
10
+ area_code_or_prefix = (10 + rand(100 - 10)).to_s
11
+ local_number = [(100 + rand(1000 - 100)).to_s, (100 + rand(1000 - 100)).to_s]
12
+ sample_number = "+#{country_prefix} (0) #{area_code_or_prefix}-#{local_number[0]}-#{local_number[1]}"
13
+ normalized_number = country_prefix + area_code_or_prefix + local_number[0] + local_number[1]
14
+ phone_number_assertions[sample_number] = {
15
+ "number" => normalized_number, "country_id" => country_id, "country_code" => country_prefix,
16
+ "area_code_or_prefix" => area_code_or_prefix, "local_number" => local_number.join
17
+ }
18
+ end
19
+
20
+ phone_number_assertions.each do |sample_number, assertions|
21
+ yield sample_number, assertions
22
+ end
23
+ end
24
+
7
25
  subject { PhoneNumber.new("123456789") }
8
26
  let(:location) { double(Torasup::Location).as_null_object }
9
27
  let(:operator) { double(Torasup::Operator).as_null_object }
@@ -54,7 +72,6 @@ module Torasup
54
72
  end
55
73
 
56
74
  shared_examples_for "a phone number" do
57
-
58
75
  before do
59
76
  Torasup::Location.stub(:new).and_return(location)
60
77
  Torasup::Operator.stub(:new).and_return(operator)
@@ -80,10 +97,6 @@ module Torasup
80
97
  end
81
98
 
82
99
  context "using the standard data" do
83
- before do
84
- configure_with_custom_data(false)
85
- end
86
-
87
100
  it_should_behave_like "a phone number" do
88
101
  let(:options) { {} }
89
102
  end
data/torasup.gemspec CHANGED
@@ -24,4 +24,5 @@ Gem::Specification.new do |gem|
24
24
 
25
25
  gem.add_development_dependency "rspec"
26
26
  gem.add_development_dependency "rake"
27
+ gem.add_development_dependency "coveralls"
27
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: torasup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Wilkie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-30 00:00:00.000000000 Z
11
+ date: 2013-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: countries
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: '"Retuns metadata about a phone number such as operator, area code and
84
98
  more"'
85
99
  email: