torasup 0.0.7 → 0.0.8

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: 9dbd5a2adc5614dce03ce4d40f2e98ddab6b06f1
4
- data.tar.gz: 28562f9426b2ae900c513865c410f08e24473210
3
+ metadata.gz: 697f9e78d549bb0018721944ca2c00c4a8405602
4
+ data.tar.gz: 8f2d17ead469e759480bfc72de7e50246f5de871
5
5
  SHA512:
6
- metadata.gz: c422d74526c12d04d2db42e69c871df37ec2a7da73845130d08b49bdd6291e4e76efdf43bfbf8bb8ef4225b6b65635dfe6a9ab828161e9fd6c8fa9dfb08ded50
7
- data.tar.gz: 64527d7bdbbdfe6ab02762ff7958802d782f5e211b91bd7ab9d1d67fa5a3f159e683a79a1e496f8aadfda6d9589f8769c244b4bed2bcc291cbcd8ea0fce73e77
6
+ metadata.gz: e12b61733c2f54c37990b432b62916e65195d54e87588567bd510cb118b72b7b12cae3d0c306f51cd7aca6f720e18e54db7187203f83a35159c39ffa1058290e
7
+ data.tar.gz: cef6cb7719d64a6536daa4dc0db6b27685d7088156bc2f241916a9dbc354069aacbf4ac70e865e997b917559523a174e0089efcda985d203dac602308051bffe
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ vendor/ruby
data/.travis.yml CHANGED
@@ -1,3 +1,5 @@
1
1
  rvm:
2
2
  - 1.9.3
3
3
  - 2.0.0
4
+ - 2.1.5
5
+ - 2.2.0
data/README.md CHANGED
@@ -86,6 +86,7 @@ kh:
86
86
  name: Hello
87
87
  my_custom_property: hello-foo
88
88
  my_custom_interpolated_property: "hello-%{interpolation}"
89
+ my_custom_boolean_property: true
89
90
  prefixes:
90
91
  - '15'
91
92
  - '16'
@@ -114,6 +115,9 @@ op.my_custom_property
114
115
 
115
116
  op.my_custom_interpolated_property(:interpolation => "bar")
116
117
  => "hello-bar"
118
+
119
+ op.my_custom_boolean_property
120
+ => true
117
121
  ```
118
122
 
119
123
  ### Accessing Operator Metadata
@@ -50,6 +50,7 @@ kh:
50
50
  metadata:
51
51
  name: "Beeline"
52
52
  prefixes:
53
+ - "31"
53
54
  - "60"
54
55
  - "66"
55
56
  - "67"
@@ -79,6 +80,7 @@ kh:
79
80
  prefixes:
80
81
  - '97'
81
82
  - '88'
83
+ - '71'
82
84
  qb:
83
85
  metadata:
84
86
  name: "Qb"
@@ -87,3 +89,15 @@ kh:
87
89
  - '80'
88
90
  - '83'
89
91
  - '84'
92
+ excell:
93
+ metadata:
94
+ name: "Excell"
95
+ prefixes:
96
+ - '18'
97
+ cootel:
98
+ metadata:
99
+ name: "CooTel"
100
+ prefixes:
101
+ - '38'
102
+ area_code_prefixes:
103
+ - '47'
@@ -9,13 +9,12 @@ module Torasup
9
9
 
10
10
  def method_missing(method, interpolations = {})
11
11
  value = Torasup.prefix_data(full_prefix)[method.to_s]
12
- if value
13
- interpolated_result = value.dup
14
- interpolations.each do |interpolation, interpolated_value|
15
- interpolated_result.gsub!("%{#{interpolation}}", interpolated_value)
16
- end
17
- interpolated_result
12
+ return value unless value.is_a?(String)
13
+ interpolated_result = value.dup
14
+ interpolations.each do |interpolation, interpolated_value|
15
+ interpolated_result.gsub!("%{#{interpolation}}", interpolated_value.to_s)
18
16
  end
17
+ interpolated_result
19
18
  end
20
19
 
21
20
  def self.registered
@@ -9,6 +9,7 @@ module Torasup
9
9
  private
10
10
 
11
11
  def parse_phone_number(number)
12
+ raise "Not a vaild number" unless Phony.plausible?(number)
12
13
  @number = Phony.normalize(number)
13
14
  number_parts = split_number
14
15
  @country_code = number_parts.shift
@@ -1,6 +1,9 @@
1
1
  module Torasup
2
2
  module Test
3
3
  module Helpers
4
+
5
+ private
6
+
4
7
  def yaml_file(filename)
5
8
  raise "Override this method to return the full path of the yaml spec"
6
9
  end
@@ -27,30 +30,39 @@ module Torasup
27
30
  operator_assertions = {}
28
31
  with_pstn_data(options) do |country_id, country_data, country_prefix|
29
32
  operator_assertions[country_prefix] = {}
33
+ local_number = country_data["local_number"]
30
34
  default_assertions = {"country_code" => country_prefix}
31
35
  with_operator_data(country_id, options) do |operator, operator_data|
32
36
  default_operator_assertions = operator_data["assertions"].merge("country_id" => country_id, "id" => operator).merge(default_assertions)
33
37
  with_operator_area_codes(country_data, operator_data) do |area_code_prefix, area_code, area|
34
- operator_assertions[country_prefix][area_code] = {}
35
- local_number = ("0" * (6 - area_code_prefix.length))
36
- unresolved_number = area_code_prefix + local_number
37
- operator_assertions[country_prefix][area_code][unresolved_number] = default_operator_assertions.merge(
38
- "area_code" => area_code, "prefix" => area_code_prefix, "local_number" => local_number
38
+ area_code_assertions = operator_assertions[country_prefix][area_code] ||= {}
39
+ area_code_assertions[area_code_prefix] = {}
40
+ custom_local_number = local_number.dup[0..(6 - area_code_prefix.length - 1)]
41
+ unresolved_number = area_code_prefix + custom_local_number
42
+ area_code_assertions[area_code_prefix][custom_local_number] = default_operator_assertions.merge(
43
+ "area_code" => area_code, "prefix" => area_code_prefix, "local_number" => custom_local_number
39
44
  )
40
45
  end
41
46
  with_operator_prefixes(operator_data) do |prefix|
42
- operator_assertions[country_prefix][prefix] = {}
43
- local_number = ("0" * 6)
44
- operator_assertions[country_prefix][prefix][local_number] = default_operator_assertions.merge(
47
+ if prefix.is_a?(Hash)
48
+ custom_local_number = prefix.values.first
49
+ prefix = prefix.keys.first
50
+ end
51
+ prefix_assertions = operator_assertions[country_prefix][prefix] = {}
52
+ no_area_code_assertions = prefix_assertions[nil] = {}
53
+ no_area_code_assertions[custom_local_number || local_number] = default_operator_assertions.merge(
45
54
  "prefix" => prefix, "area_code" => nil
46
55
  )
47
56
  end
48
57
  end
49
58
  end
50
59
  operator_assertions.each do |country_prefix, country_assertions|
51
- country_assertions.each do |area_code_or_prefix, area_code_or_prefix_assertions|
52
- area_code_or_prefix_assertions.each do |unresolved_local_number, assertions|
53
- yield [country_prefix, area_code_or_prefix, unresolved_local_number], assertions
60
+ country_assertions.each do |area_code_or_prefix, area_code_assertions|
61
+ area_code_assertions.each do |area_code_prefix, local_numbers|
62
+ local_numbers.each do |local_number, assertions|
63
+ unresolved_local_number = area_code_prefix.to_s + local_number
64
+ yield [country_prefix, area_code_or_prefix, unresolved_local_number], assertions
65
+ end
54
66
  end
55
67
  end
56
68
  end
@@ -89,13 +101,12 @@ module Torasup
89
101
  end
90
102
 
91
103
  def interpolated_assertion(assertion, interpolations = {})
92
- if assertion
93
- interpolated_result = assertion.dup
94
- interpolations.each do |interpolation, value|
95
- interpolated_result.gsub!("%{#{interpolation}}", value)
96
- end
97
- interpolated_result
104
+ return assertion unless assertion.is_a?(String)
105
+ interpolated_result = assertion.dup
106
+ interpolations.each do |interpolation, value|
107
+ interpolated_result.gsub!("%{#{interpolation}}", value.to_s)
98
108
  end
109
+ interpolated_result
99
110
  end
100
111
  end
101
112
  end
@@ -1,3 +1,3 @@
1
1
  module Torasup
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -4,5 +4,12 @@ Coveralls.wear!
4
4
 
5
5
  RSpec.configure do |config|
6
6
  Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
7
- config.treat_symbols_as_metadata_keys_with_true_values = true
7
+
8
+ config.expect_with :rspec do |c|
9
+ c.syntax = [:should, :expect]
10
+ end
11
+
12
+ config.mock_with :rspec do |mocks|
13
+ mocks.syntax = [:should, :expect]
14
+ end
8
15
  end
@@ -9,6 +9,7 @@ kh:
9
9
  name: Hello
10
10
  my_custom_property: hello-foo
11
11
  my_custom_interpolated_property: "hello-%{interpolation}"
12
+ my_custom_boolean_property: true
12
13
  prefixes:
13
14
  - '15'
14
15
  - '16'
@@ -9,6 +9,7 @@ kh:
9
9
  name: "Hello"
10
10
  my_custom_property: "hello-foo"
11
11
  my_custom_interpolated_property: "hello-%{interpolation}"
12
+ my_custom_boolean_property: true
12
13
  prefixes:
13
14
  - '15'
14
15
  - '16'
@@ -4,6 +4,7 @@
4
4
  kh:
5
5
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_Cambodia
6
6
  prefix: '855'
7
+ local_number: "234567"
7
8
  area_codes:
8
9
  '23': Phnom Penh
9
10
  '24': Kandal
@@ -44,7 +45,7 @@ kh:
44
45
  - '86'
45
46
  - '87'
46
47
  - '93'
47
- - '96'
48
+ - '96': "2345678"
48
49
  - '98'
49
50
  area_code_prefixes:
50
51
  - '45'
@@ -52,6 +53,7 @@ kh:
52
53
  assertions:
53
54
  name: Beeline
54
55
  prefixes:
56
+ - '31': "2345678"
55
57
  - '60'
56
58
  - '66'
57
59
  - '67'
@@ -72,15 +74,16 @@ kh:
72
74
  - '95'
73
75
  - '11'
74
76
  - '61'
75
- - '76'
77
+ - '76': "2345678"
76
78
  - '85'
77
79
  - '99'
78
80
  metfone:
79
81
  assertions:
80
82
  name: Metfone
81
83
  prefixes:
82
- - '97'
83
- - '88'
84
+ - '97': "2345678"
85
+ - '88': "2345678"
86
+ - '71': "2345678"
84
87
  qb:
85
88
  assertions:
86
89
  name: Qb
@@ -89,3 +92,15 @@ kh:
89
92
  - '80'
90
93
  - '83'
91
94
  - '84'
95
+ excell:
96
+ assertions:
97
+ name: Excell
98
+ prefixes:
99
+ - '18'
100
+ cootel:
101
+ assertions:
102
+ name: CooTel
103
+ prefixes:
104
+ - '38': "2345678"
105
+ area_code_prefixes:
106
+ - '47'
@@ -63,10 +63,10 @@ module Torasup
63
63
  subject = Operator.new(*number_parts)
64
64
  assertions.each do |method, assertion|
65
65
  args = []
66
- args << {:interpolation => "interpolation"} unless subject.respond_to?(method)
66
+ args << {:interpolation => nil} unless subject.respond_to?(method)
67
67
  result = subject.send(method, *args)
68
68
  result_error = result.nil? ? "nil" : "'#{result}'"
69
- result.should(eq(interpolated_assertion(assertion, :interpolation => "interpolation")), "expected Operator.new('#{number_parts}').#{method} to return '#{assertion}' but got #{result_error}")
69
+ result.should(eq(interpolated_assertion(assertion, :interpolation => nil)), "expected Operator.new('#{number_parts}').#{method} to return '#{assertion}' but got #{result_error}")
70
70
  end
71
71
  end
72
72
  end
@@ -6,14 +6,12 @@ module Torasup
6
6
 
7
7
  def with_phone_numbers(options = {}, &block)
8
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]
9
+ with_operators(options) do |number_parts, assertions|
10
+ number = number_parts.join
11
+ sample_number = "+#{number}"
14
12
  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
13
+ "number" => number, "country_id" => assertions["country_id"], "country_code" => assertions["country_code"],
14
+ "area_code_or_prefix" => assertions["area_code"] || assertions["prefix"], "local_number" => number_parts.last
17
15
  }
18
16
  end
19
17
 
@@ -22,7 +20,7 @@ module Torasup
22
20
  end
23
21
  end
24
22
 
25
- subject { PhoneNumber.new("123456789") }
23
+ subject { PhoneNumber.new("85512234567") }
26
24
  let(:location) { double(Torasup::Location).as_null_object }
27
25
  let(:operator) { double(Torasup::Operator).as_null_object }
28
26
 
data/torasup.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
19
19
  gem.require_paths = ["lib"]
20
20
 
21
21
  gem.add_runtime_dependency "countries"
22
- gem.add_runtime_dependency "phony"
22
+ gem.add_runtime_dependency "phony", '>= 2.10.2'
23
23
  gem.add_runtime_dependency "deep_merge"
24
24
 
25
25
  gem.add_development_dependency "rspec"
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: torasup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
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-09-04 00:00:00.000000000 Z
11
+ date: 2015-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: countries
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: phony
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 2.10.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 2.10.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: deep_merge
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: coveralls
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  description: '"Retuns metadata about a phone number such as operator, area code and
@@ -102,8 +102,8 @@ executables: []
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
- - .gitignore
106
- - .travis.yml
105
+ - ".gitignore"
106
+ - ".travis.yml"
107
107
  - Gemfile
108
108
  - LICENSE.txt
109
109
  - README.md
@@ -136,17 +136,17 @@ require_paths:
136
136
  - lib
137
137
  required_ruby_version: !ruby/object:Gem::Requirement
138
138
  requirements:
139
- - - '>='
139
+ - - ">="
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  requirements:
144
- - - '>='
144
+ - - ">="
145
145
  - !ruby/object:Gem::Version
146
146
  version: '0'
147
147
  requirements: []
148
148
  rubyforge_project:
149
- rubygems_version: 2.0.3
149
+ rubygems_version: 2.4.5
150
150
  signing_key:
151
151
  specification_version: 4
152
152
  summary: '"Retuns metadata about a phone number such as operator, area code and more"'