torasup 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +5 -0
- data/lib/torasup/operator.rb +14 -0
- data/lib/torasup/test/helpers.rb +1 -1
- data/lib/torasup/version.rb +1 -1
- data/lib/torasup.rb +5 -1
- data/spec/torasup/operator_spec.rb +16 -0
- data/spec/torasup/phone_number_spec.rb +2 -2
- metadata +20 -41
- data/spec/torasup_spec.rb +0 -4
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 58441e57888b60e74180d3839b58228c9173dc1d
|
4
|
+
data.tar.gz: e5ef2e5a914ae3fe5948226b26e2847a4d493ae8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 458f7e38e714dbcabc1205d5036f7e769c691bd65596a69fa79c19dfece32c9781853b0e692b02d86e457096f34ecf90874fc7c4be895c19843d5626aecce598
|
7
|
+
data.tar.gz: c05b9cbec59b960f4f75404a3a1d8cda1a27e3e21e1c2c66d9b26f0b261f9069b06b4e92c4d324b141263c117cd2147a26e9ba7b9dd75927d0d1e95851dc2e76
|
data/README.md
CHANGED
@@ -101,6 +101,11 @@ Sometimes it maybe necessary to override the data that Torasup provides. For exa
|
|
101
101
|
> op.my_custom_interpolated_property(:interpolation => "bar")
|
102
102
|
=> "hello-bar"
|
103
103
|
|
104
|
+
### Accessing Operator Metadata
|
105
|
+
|
106
|
+
> Torasup::Operator.all["kh"]["metfone"]["prefixes"]
|
107
|
+
=> ["85597", "85588"]
|
108
|
+
|
104
109
|
### Registering Operators
|
105
110
|
|
106
111
|
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.
|
data/lib/torasup/operator.rb
CHANGED
@@ -22,6 +22,20 @@ module Torasup
|
|
22
22
|
Torasup.registered_prefixes
|
23
23
|
end
|
24
24
|
|
25
|
+
def self.all
|
26
|
+
operators = {}
|
27
|
+
Torasup.prefixes.each do |prefix, metadata|
|
28
|
+
prefix_country_id = metadata["country_id"]
|
29
|
+
country_operators = operators[prefix_country_id] ||= {}
|
30
|
+
prefix_operator_id = metadata["id"]
|
31
|
+
operator_metadata = country_operators[prefix_operator_id] ||= metadata.dup
|
32
|
+
operator_metadata.delete("prefix")
|
33
|
+
prefixes = operator_metadata["prefixes"] ||= []
|
34
|
+
prefixes << prefix
|
35
|
+
end
|
36
|
+
operators
|
37
|
+
end
|
38
|
+
|
25
39
|
private
|
26
40
|
|
27
41
|
def parse_phone_number(area_code_or_prefix, unresolved_local_number)
|
data/lib/torasup/test/helpers.rb
CHANGED
@@ -32,7 +32,7 @@ module Torasup
|
|
32
32
|
operator_assertions[country_prefix] = {}
|
33
33
|
default_assertions = {"country_code" => country_prefix}
|
34
34
|
with_operator_data(country_id, options) do |operator, operator_data|
|
35
|
-
default_operator_assertions = operator_data["assertions"].merge("id" => operator).merge(default_assertions)
|
35
|
+
default_operator_assertions = operator_data["assertions"].merge("country_id" => country_id, "id" => operator).merge(default_assertions)
|
36
36
|
with_operator_area_codes(country_data, operator_data) do |area_code_prefix, area_code, area|
|
37
37
|
operator_assertions[country_prefix][area_code] = {}
|
38
38
|
local_number = ("0" * (6 - area_code_prefix.length))
|
data/lib/torasup/version.rb
CHANGED
data/lib/torasup.rb
CHANGED
@@ -51,6 +51,10 @@ module Torasup
|
|
51
51
|
@registered_pstn_prefixes.keys
|
52
52
|
end
|
53
53
|
|
54
|
+
def prefixes
|
55
|
+
@pstn_prefixes.dup
|
56
|
+
end
|
57
|
+
|
54
58
|
private
|
55
59
|
|
56
60
|
def load_pstn_prefixes!
|
@@ -100,7 +104,7 @@ module Torasup
|
|
100
104
|
end
|
101
105
|
|
102
106
|
def operator_metadata(country_id, operator)
|
103
|
-
{"id" => operator}.merge(operator_data(country_id, operator)["metadata"] || {})
|
107
|
+
{"country_id" => country_id, "id" => operator}.merge(operator_data(country_id, operator)["metadata"] || {})
|
104
108
|
end
|
105
109
|
|
106
110
|
def operator_area_code_prefixes(country_id, operator)
|
@@ -29,6 +29,22 @@ module Torasup
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
describe ".all" do
|
33
|
+
it "should return all the operators with their metadata" do
|
34
|
+
operators = Operator.all
|
35
|
+
operators = Operator.all # run it twice to highlight the duplication problem
|
36
|
+
with_operators do |number_parts, assertions|
|
37
|
+
operator = operators[assertions["country_id"]][assertions["id"]]
|
38
|
+
operator["country_id"].should == assertions["country_id"]
|
39
|
+
operator["id"].should == assertions["id"]
|
40
|
+
operator["prefixes"].should == operator["prefixes"].uniq
|
41
|
+
operator["prefixes"].should include(
|
42
|
+
assertions["country_code"].to_s + assertions["area_code"].to_s + assertions["prefix"].to_s
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
32
48
|
shared_examples_for "an operator" do
|
33
49
|
it "should return all the operator metadata" do
|
34
50
|
with_operators(options) do |number_parts, assertions|
|
@@ -5,8 +5,8 @@ module Torasup
|
|
5
5
|
include PstnHelpers
|
6
6
|
|
7
7
|
subject { PhoneNumber.new("123456789") }
|
8
|
-
let(:location) {
|
9
|
-
let(:operator) {
|
8
|
+
let(:location) { double(Torasup::Location).as_null_object }
|
9
|
+
let(:operator) { double(Torasup::Operator).as_null_object }
|
10
10
|
|
11
11
|
describe "#location" do
|
12
12
|
it "should return an instance of Torasup::Location" do
|
metadata
CHANGED
@@ -1,98 +1,87 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: torasup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- David Wilkie
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-08-28 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: countries
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: phony
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: deep_merge
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: rspec
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: rake
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - '>='
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - '>='
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
|
-
description:
|
95
|
-
|
83
|
+
description: '"Retuns metadata about a phone number such as operator, area code and
|
84
|
+
more"'
|
96
85
|
email:
|
97
86
|
- dwilkie@gmail.com
|
98
87
|
executables: []
|
@@ -122,39 +111,30 @@ files:
|
|
122
111
|
- spec/torasup/location_spec.rb
|
123
112
|
- spec/torasup/operator_spec.rb
|
124
113
|
- spec/torasup/phone_number_spec.rb
|
125
|
-
- spec/torasup_spec.rb
|
126
114
|
- torasup.gemspec
|
127
115
|
homepage: https://github.com/dwilkie/torasup/
|
128
116
|
licenses: []
|
117
|
+
metadata: {}
|
129
118
|
post_install_message:
|
130
119
|
rdoc_options: []
|
131
120
|
require_paths:
|
132
121
|
- lib
|
133
122
|
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
-
none: false
|
135
123
|
requirements:
|
136
|
-
- -
|
124
|
+
- - '>='
|
137
125
|
- !ruby/object:Gem::Version
|
138
126
|
version: '0'
|
139
|
-
segments:
|
140
|
-
- 0
|
141
|
-
hash: -283226445
|
142
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
-
none: false
|
144
128
|
requirements:
|
145
|
-
- -
|
129
|
+
- - '>='
|
146
130
|
- !ruby/object:Gem::Version
|
147
131
|
version: '0'
|
148
|
-
segments:
|
149
|
-
- 0
|
150
|
-
hash: -283226445
|
151
132
|
requirements: []
|
152
133
|
rubyforge_project:
|
153
|
-
rubygems_version:
|
134
|
+
rubygems_version: 2.0.3
|
154
135
|
signing_key:
|
155
|
-
specification_version:
|
156
|
-
summary:
|
157
|
-
more"'
|
136
|
+
specification_version: 4
|
137
|
+
summary: '"Retuns metadata about a phone number such as operator, area code and more"'
|
158
138
|
test_files:
|
159
139
|
- spec/spec_helper.rb
|
160
140
|
- spec/support/custom_pstn.yaml
|
@@ -165,4 +145,3 @@ test_files:
|
|
165
145
|
- spec/torasup/location_spec.rb
|
166
146
|
- spec/torasup/operator_spec.rb
|
167
147
|
- spec/torasup/phone_number_spec.rb
|
168
|
-
- spec/torasup_spec.rb
|
data/spec/torasup_spec.rb
DELETED