torasup 0.1.2 → 0.3.0

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
- SHA1:
3
- metadata.gz: 96bf8ed2c9765fec7804b2c8343aff650d7dbbd1
4
- data.tar.gz: 5d8a1a2613210ea556aff93610538158da20a355
2
+ SHA256:
3
+ metadata.gz: eda949d2ce20b1045480ea61d4c961cd2dc382d4642f3c0a6db6e1f1e5c24d4f
4
+ data.tar.gz: 65bb3f5b2db59ac77f15560b6bf750f7b3ec3dece345bad5f7fb055d48ed8aa5
5
5
  SHA512:
6
- metadata.gz: 7e03c8b8f86d4c72a48df00875a4f0014f0fffeb30ea38ab88f54f8580532a4e437ddd03f9d71639811ba31774ab66e6221321c4d5eb0ac5ccce67b849dd542e
7
- data.tar.gz: 5aa7c81f1ed11e2afa051763334806dda3576ead4a25e910c98cd2a3d920c41497fad77dca206e0483557190b54e79902f53b30832e7cae5efe264887a6e105f
6
+ metadata.gz: 34c1fbddf8ee267a62216a9d609b9603a0ebac45937f372a6295d48f8226ed11b4c1df19a424b91e0a0253938b6c0fc6dcef8162e50580885a3d8527490c4ca9
7
+ data.tar.gz: d98791b3e7f302b79976efbcbe544a0af66f798a183cd98b75d34c37af45136b91389d2b8fd26430f58cf62cc524ae252e45f9ad3f34837116e2983d6c466de7
@@ -0,0 +1,35 @@
1
+ name: Build
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+
13
+ - name: Set up Ruby
14
+ uses: actions/setup-ruby@v1
15
+ with:
16
+ ruby-version: 2.7.x
17
+
18
+ - name: Install Dependencies
19
+ run: |
20
+ gem install bundler
21
+ bundle install --jobs 4 --retry 3
22
+
23
+ - name: Deploy
24
+ if: github.ref == 'refs/heads/master' && !contains(github.event.commits[0].message, '[skip deploy]')
25
+ env:
26
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27
+ GEM_HOST_API_KEY: ${{ secrets.GEM_HOST_API_KEY }}
28
+
29
+ run: |
30
+ git config --global user.email "dwilkie@gmail.com"
31
+ git config --global user.name "David Wilkie"
32
+ mkdir -p ~/.gem
33
+ echo -e "---\r\n:rubygems_api_key: $GEM_HOST_API_KEY" > ~/.gem/credentials
34
+ chmod 0600 ~/.gem/credentials
35
+ bundle exec rake release
@@ -0,0 +1,11 @@
1
+ Style/FrozenStringLiteralComment:
2
+ Enabled: false
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Metrics/LineLength:
8
+ Max: 100
9
+
10
+ Style/Documentation:
11
+ Enabled: false
@@ -0,0 +1 @@
1
+ ruby 2.7.1
data/Gemfile CHANGED
@@ -1,9 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- git_source(:github) do |repo_name|
4
- repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
5
- "https://github.com/#{repo_name}.git"
6
- end
1
+ source "https://rubygems.org"
7
2
 
8
3
  # Specify your gem's dependencies in torasup.gemspec
9
4
  gemspec
data/README.md CHANGED
@@ -2,7 +2,7 @@
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) [![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)
5
+ ![Build](https://github.com/somleng/torasup/workflows/Build/badge.svg)
6
6
 
7
7
  ## Installation
8
8
 
@@ -89,7 +89,7 @@ Torasup.prefixes["8552345"]
89
89
 
90
90
  ### Overriding Data
91
91
 
92
- 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.
92
+ 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/somleng/torasup/blob/master/spec/support/custom_pstn.yaml) for more info. e.g.
93
93
 
94
94
  ```yaml
95
95
  # my_pstn_data.yaml
@@ -185,7 +185,7 @@ Torasup::PhoneNumber.new("+1 415-234 567").country_id
185
185
 
186
186
  ## Testing
187
187
 
188
- Torasup exposes a few test helpers methods which you can use in your tests. See [the helper module](https://github.com/dwilkie/torasup/blob/master/lib/torasup/test/helpers.rb) for more info.
188
+ Torasup exposes a few test helpers methods which you can use in your tests. See [the helper module](https://github.com/somleng/torasup/blob/master/lib/torasup/test/helpers.rb) for more info.
189
189
 
190
190
  Here's an example using rspec:
191
191
 
@@ -203,7 +203,7 @@ describe User do
203
203
  end
204
204
 
205
205
  # provide a custom spec file for example see:
206
- # see https://github.com/dwilkie/torasup/blob/master/spec/support/custom_pstn_spec.yaml
206
+ # see https://github.com/somleng/torasup/blob/master/spec/support/custom_pstn_spec.yaml
207
207
  def pstn_data(custom_spec = nil)
208
208
  super("custom_operators_spec.yaml")
209
209
  end
@@ -237,8 +237,8 @@ Sample numbers and assertions are only yielded for the operators defined in `ASS
237
237
 
238
238
  ### Data
239
239
 
240
- When contributing data please ensure that you create or edit an entry in the [pstn spec](https://github.com/dwilkie/torasup/tree/master/spec/torasup/spec/support_pstn_spec.rb). This ensures the integrity of the data.
240
+ When contributing data please ensure that you create or edit an entry in the [pstn spec](https://github.com/somleng/torasup/tree/master/spec/torasup/spec/support_pstn_spec.rb). This ensures the integrity of the data.
241
241
 
242
- Please also include a link to Wikipedia article which verifies your data. See the [current psdn spec](https://github.com/dwilkie/torasup/blob/master/spec/support/pstn_spec.yaml) for an example that links to [Wikipedia](http://en.wikipedia.org/wiki/Telecommunications_in_Cambodia#Mobile_networks).
242
+ Please also include a link to Wikipedia article which verifies your data. See the [current psdn spec](https://github.com/somleng/torasup/blob/master/spec/support/pstn_spec.yaml) for an example that links to [Wikipedia](http://en.wikipedia.org/wiki/Telecommunications_in_Cambodia#Mobile_networks).
243
243
 
244
244
  If you obtained operator prefixes from another source please clearly add these prefixes to the appropriate Wikipedia article and reference it if necessary. This helps ensure the accuracy of the gem.
@@ -1,7 +1,7 @@
1
- require 'yaml'
2
- require 'phony'
3
- require 'countries'
4
- require 'deep_merge/rails_compat'
1
+ require "yaml"
2
+ require "phony"
3
+ require "countries"
4
+ require "deep_merge/rails_compat"
5
5
 
6
6
  require "torasup/version"
7
7
  require "torasup/configuration"
@@ -10,12 +10,16 @@ require "torasup/operator"
10
10
  require "torasup/location"
11
11
 
12
12
  module Torasup
13
+ ALL_PREFIXES_KEYS = ["*", "all"].freeze
14
+ DEFAULT_OPERATOR_PREFIX_MIN = "10".freeze
15
+ DEFAULT_OPERATOR_PREFIX_MAX = "99".freeze
16
+
13
17
  module Test
14
- autoload :Helpers, 'torasup/test/helpers'
18
+ autoload :Helpers, "torasup/test/helpers"
15
19
  end
16
20
 
17
21
  class << self
18
- def configure(&block)
22
+ def configure
19
23
  yield(configuration)
20
24
  end
21
25
 
@@ -23,12 +27,14 @@ module Torasup
23
27
  @international_dialing_codes = {}
24
28
  ISO3166::Country.all.each do |country|
25
29
  dialing_code = country.country_code
26
- @international_dialing_codes[dialing_code] = country.alpha2 if !@international_dialing_codes[dialing_code] || configuration.default_countries.include?(country.alpha2)
30
+ if !@international_dialing_codes[dialing_code] || configuration.default_countries.include?(country.alpha2)
31
+ @international_dialing_codes[dialing_code] = country.alpha2
32
+ end
27
33
  end
28
34
  end
29
35
 
30
36
  def load_pstn_data!
31
- @pstn_data = load_yaml_file(File.join(File.dirname(__FILE__), 'torasup/data/pstn.yaml'))
37
+ @pstn_data = load_yaml_file(File.join(File.dirname(__FILE__), "torasup/data/pstn.yaml"))
32
38
  configuration.custom_pstn_data_files.compact.each do |pstn_data_file|
33
39
  @pstn_data.deeper_merge!(
34
40
  load_yaml_file(pstn_data_file)
@@ -38,7 +44,7 @@ module Torasup
38
44
  end
39
45
 
40
46
  def country_id(country_code)
41
- @international_dialing_codes[country_code].downcase if @international_dialing_codes[country_code]
47
+ @international_dialing_codes[country_code]&.downcase
42
48
  end
43
49
 
44
50
  def area_code(country_id, code)
@@ -76,7 +82,9 @@ module Torasup
76
82
  ).merge(prefix_data)
77
83
 
78
84
  @pstn_prefixes[operator_prefix] = prefix_properties
79
- @registered_pstn_prefixes[operator_prefix] = prefix_properties if operator_registered?(country_id, operator)
85
+ if operator_registered?(country_id, operator)
86
+ @registered_pstn_prefixes[operator_prefix] = prefix_properties
87
+ end
80
88
  end
81
89
  end
82
90
  end
@@ -115,7 +123,7 @@ module Torasup
115
123
  end
116
124
 
117
125
  def operator_metadata(country_id, operator)
118
- {"country_id" => country_id, "id" => operator}.merge(operator_data(country_id, operator)["metadata"] || {})
126
+ { "country_id" => country_id, "id" => operator }.merge(operator_data(country_id, operator)["metadata"] || {})
119
127
  end
120
128
 
121
129
  def operator_area_code_prefixes(country_id, operator)
@@ -125,7 +133,7 @@ module Torasup
125
133
  def prefix_defaults(country_properties, operator_properties, prefix_properties)
126
134
  defaults = {}
127
135
  prefix_type = prefix_properties["type"]
128
- [:min, :max, :pattern].each do |prefix_key|
136
+ %i[min max pattern].each do |prefix_key|
129
137
  result_key = "subscriber_number_#{prefix_key}"
130
138
  default_key = "default_#{prefix_type}_#{result_key}"
131
139
  result_value = prefix_properties[result_key] || operator_properties[default_key] || country_properties[default_key]
@@ -137,11 +145,18 @@ module Torasup
137
145
  def operator_mobile_prefixes(country_id, operator)
138
146
  full_prefixes = {}
139
147
  operator_data = operator_data(country_id, operator)
140
- mobile_prefixes = array_to_hash(operator_data["prefixes"] || [])
148
+ if operator_data["prefixes"].is_a?(String) && ALL_PREFIXES_KEYS.include?(operator_data["prefixes"])
149
+ operator_prefix_min = country_data(country_id).fetch("operator_prefix_min", DEFAULT_OPERATOR_PREFIX_MIN)
150
+ operator_prefix_max = country_data(country_id).fetch("operator_prefix_max", DEFAULT_OPERATOR_PREFIX_MAX)
151
+ prefixes = (operator_prefix_min.to_s..operator_prefix_max).to_a
152
+ end
153
+ prefixes ||= operator_data["prefixes"]
154
+ prefixes ||= []
155
+ mobile_prefixes = array_to_hash(prefixes)
141
156
  mobile_prefixes.each do |mobile_prefix, prefix_metadata|
142
157
  full_prefixes[operator_full_prefix(country_id, mobile_prefix)] = {
143
158
  "type" => "mobile",
144
- "prefix" => mobile_prefix,
159
+ "prefix" => mobile_prefix
145
160
  }.merge(prefix_metadata)
146
161
  end
147
162
  full_prefixes
@@ -155,7 +170,7 @@ module Torasup
155
170
  operator_prefixes = operator_mobile_prefixes(country_id, operator)
156
171
  area_code_prefixes = array_to_hash(operator_area_code_prefixes(country_id, operator))
157
172
  area_code_prefixes.each do |operator_area_code_prefix, prefix_metadata|
158
- area_codes(country_id).each do |area_code, area|
173
+ area_codes(country_id).each do |area_code, _area|
159
174
  operator_prefixes[operator_full_prefix(country_id, area_code, operator_area_code_prefix)] = {
160
175
  "type" => "landline",
161
176
  "prefix" => operator_area_code_prefix,
@@ -167,7 +182,7 @@ module Torasup
167
182
  end
168
183
 
169
184
  def array_to_hash(array)
170
- array.map { |n| n.is_a?(Hash) ? n : {n => {}} }.reduce(Hash.new, :merge)
185
+ array.map { |n| n.is_a?(Hash) ? n : { n => {} } }.reduce({}, :merge)
171
186
  end
172
187
  end
173
188
 
@@ -1,5 +1,5 @@
1
1
  class Configuration
2
- DEFAULT_COUNTRIES = ["US", "GB", "AU", "IT", "RU", "NO"]
2
+ DEFAULT_COUNTRIES = %w[US GB AU IT RU NO].freeze
3
3
  attr_accessor :registered_operators, :default_countries, :custom_pstn_data_files
4
4
 
5
5
  def initialize
@@ -207,3 +207,76 @@ so:
207
207
  prefixes:
208
208
  - '61'
209
209
  - '64'
210
+ sl:
211
+ # https://en.wikipedia.org/wiki/Telecommunications_in_Sierra_Leone
212
+ # https://en.wikipedia.org/wiki/List_of_mobile_network_operators_of_the_Middle_East_and_Africa#Sierra_Leone
213
+ international_dialing_code: "232"
214
+ operators:
215
+ africell:
216
+ # https://en.wikipedia.org/wiki/Africell
217
+ metadata:
218
+ name: "Africell"
219
+ prefixes:
220
+ - '30'
221
+ - '77'
222
+ - '88'
223
+ orange:
224
+ metadata:
225
+ name: "Orange"
226
+ prefixes:
227
+ - '75'
228
+ - '76'
229
+ - '78'
230
+ - '79'
231
+ br:
232
+ # https://en.wikipedia.org/wiki/Telecommunications_in_Brazil
233
+ # https://en.wikipedia.org/wiki/List_of_mobile_network_operators_of_the_Americas#Brazil
234
+ international_dialing_code: "55"
235
+
236
+ in:
237
+ # https://en.wikipedia.org/wiki/Mobile_telephone_numbering_in_India
238
+ international_dialing_code: "91"
239
+ operator_prefix_min: "6000"
240
+ operator_prefix_max: "9999"
241
+
242
+ gh:
243
+ international_dialing_code: "233"
244
+ # https://en.m.wikipedia.org/wiki/Telephone_numbers_in_Ghana
245
+ operators:
246
+ globacom:
247
+ # https://en.wikipedia.org/wiki/Glo_(company)
248
+ metadata:
249
+ name: "Globacom"
250
+ prefixes:
251
+ - '23'
252
+ mtn:
253
+ # https://en.wikipedia.org/wiki/MTN_Group
254
+ metadata:
255
+ name: "MTN"
256
+ prefixes:
257
+ - '24'
258
+ - '54'
259
+ - '55'
260
+ - '59'
261
+ airtel_tigo:
262
+ # https://en.wikipedia.org/wiki/Airtel_Africa#Tigo_Ghana_merger
263
+ metadata:
264
+ name: "AirtelTigo"
265
+ prefixes:
266
+ - '27'
267
+ - '57'
268
+ - '26'
269
+ - '56'
270
+ expresso:
271
+ # https://en.wikipedia.org/wiki/Expresso_Telecom
272
+ metadata:
273
+ name: "Expresso"
274
+ prefixes:
275
+ - '28'
276
+ vodafone:
277
+ # https://en.wikipedia.org/wiki/Vodafone_Ghana
278
+ metadata:
279
+ name: "Vodafone"
280
+ prefixes:
281
+ - '20'
282
+ - '50'
@@ -17,6 +17,7 @@ module Torasup
17
17
 
18
18
  def parse_phone_number(number)
19
19
  raise "Not a vaild number" unless Phony.plausible?(number)
20
+
20
21
  @number = Phony.normalize(number)
21
22
  number_parts = split_number
22
23
  @country_code = number_parts.shift
@@ -1,10 +1,9 @@
1
1
  module Torasup
2
2
  module Test
3
3
  module Helpers
4
-
5
4
  private
6
5
 
7
- def yaml_file(filename)
6
+ def yaml_file(_filename)
8
7
  raise "Override this method to return the full path of the yaml spec"
9
8
  end
10
9
 
@@ -26,17 +25,17 @@ module Torasup
26
25
  custom_spec ? data.deeper_merge(load_yaml_file(custom_spec)) : data
27
26
  end
28
27
 
29
- def with_operators(options = {}, &block)
28
+ def with_operators(options = {})
30
29
  operator_assertions = {}
31
30
  with_pstn_data(options) do |country_id, country_data, country_prefix|
32
31
  operator_assertions[country_prefix] = {}
33
32
  local_number = country_data["local_number"]
34
- default_assertions = {"country_code" => country_prefix}
33
+ default_assertions = { "country_code" => country_prefix }
35
34
  with_operator_data(country_id, options) do |operator, operator_data|
36
35
  default_operator_assertions = operator_data["assertions"].merge(
37
36
  "country_id" => country_id, "id" => operator
38
37
  ).merge(default_assertions)
39
- with_operator_area_codes(country_data, operator_data) do |area_code_prefix, area_code, area|
38
+ with_operator_area_codes(country_data, operator_data) do |area_code_prefix, area_code, _area|
40
39
  if area_code_prefix.is_a?(Hash)
41
40
  custom_local_number = area_code_prefix.values.first
42
41
  area_code_prefix = area_code_prefix.keys.first
@@ -58,7 +57,7 @@ module Torasup
58
57
  custom_local_number = prefix.values.first
59
58
  prefix = prefix.keys.first
60
59
  end
61
- prefix_assertions = operator_assertions[country_prefix][prefix] = {}
60
+ prefix_assertions = operator_assertions[country_prefix][prefix] = {}
62
61
  no_area_code_assertions = prefix_assertions[nil] = {}
63
62
 
64
63
  custom_local_number ||= local_number
@@ -84,21 +83,21 @@ module Torasup
84
83
  end
85
84
  end
86
85
 
87
- def with_pstn_data(options = {}, &block)
86
+ def with_pstn_data(options = {})
88
87
  pstn_data(options[:with_custom_pstn_data]).each do |country_id, country_data|
89
88
  next if options[:only_registered] && !options[:only_registered].include?(country_id)
90
89
  yield country_id, country_data, country_data["prefix"]
91
90
  end
92
91
  end
93
92
 
94
- def with_operator_data(country_id, options = {}, &block)
93
+ def with_operator_data(country_id, options = {})
95
94
  country_data(country_id, options[:with_custom_pstn_data])["operators"].each do |operator, operator_data|
96
95
  next if options[:only_registered] && !options[:only_registered][country_id].include?(operator)
97
96
  yield operator, operator_data
98
97
  end
99
98
  end
100
99
 
101
- def with_operator_area_codes(country_data, operator_data, &block)
100
+ def with_operator_area_codes(country_data, operator_data)
102
101
  (operator_data["area_code_prefixes"] || {}).each do |area_code_prefix|
103
102
  country_data["area_codes"].each do |area_code, area|
104
103
  yield area_code_prefix, area_code, area
@@ -106,7 +105,7 @@ module Torasup
106
105
  end
107
106
  end
108
107
 
109
- def with_operator_prefixes(operator_data, &block)
108
+ def with_operator_prefixes(operator_data)
110
109
  (operator_data["prefixes"] || {}).each do |prefix|
111
110
  yield prefix
112
111
  end
@@ -1,3 +1,3 @@
1
1
  module Torasup
2
- VERSION = "0.1.2"
2
+ VERSION = "0.3.0".freeze
3
3
  end
@@ -1,3 +1,8 @@
1
+ if ENV["START_SIMPLECOV"].to_i == 1
2
+ require 'simplecov'
3
+ SimpleCov.start
4
+ end
5
+
1
6
  require 'torasup'
2
7
 
3
8
  RSpec.configure do |config|
@@ -17,3 +17,17 @@ kh:
17
17
  - '87'
18
18
  area_code_prefixes:
19
19
  - '45'
20
+
21
+ in:
22
+ operators:
23
+ imimobile:
24
+ metadata:
25
+ name: "IMImobile"
26
+ prefixes: "*"
27
+
28
+ br:
29
+ operators:
30
+ mundivox:
31
+ metadata:
32
+ name: "Mundivox"
33
+ prefixes: "*"
@@ -173,3 +173,59 @@ so:
173
173
  prefixes:
174
174
  - '61'
175
175
  - '64'
176
+ sl:
177
+ prefix: "232"
178
+ local_number: "234567"
179
+ operators:
180
+ # https://en.wikipedia.org/wiki/Telecommunications_in_Sierra_Leone
181
+ # https://en.wikipedia.org/wiki/List_of_mobile_network_operators_of_the_Middle_East_and_Africa#Sierra_Leone
182
+ africell:
183
+ # https://en.wikipedia.org/wiki/Africell
184
+ assertions:
185
+ name: "Africell"
186
+ prefixes:
187
+ - '30'
188
+ - '77'
189
+ - '88'
190
+
191
+ gh:
192
+ prefix: "233"
193
+ local_number: "2437103"
194
+ operators:
195
+ # https://en.m.wikipedia.org/wiki/Telephone_numbers_in_Ghana
196
+ globacom:
197
+ # https://en.wikipedia.org/wiki/Glo_(company)
198
+ assertions:
199
+ name: "Globacom"
200
+ prefixes:
201
+ - '23'
202
+ mtn:
203
+ # https://en.wikipedia.org/wiki/MTN_Group
204
+ assertions:
205
+ name: "MTN"
206
+ prefixes:
207
+ - '24'
208
+ - '54'
209
+ - '55'
210
+ airtel_tigo:
211
+ # https://en.wikipedia.org/wiki/Airtel_Africa#Tigo_Ghana_merger
212
+ assertions:
213
+ name: "AirtelTigo"
214
+ prefixes:
215
+ - '27'
216
+ - '57'
217
+ - '26'
218
+ - '56'
219
+ expresso:
220
+ # https://en.wikipedia.org/wiki/Expresso_Telecom
221
+ assertions:
222
+ name: "Expresso"
223
+ prefixes:
224
+ - '28'
225
+ vodafone:
226
+ # https://en.wikipedia.org/wiki/Vodafone_Ghana
227
+ assertions:
228
+ name: "Vodafone"
229
+ prefixes:
230
+ - '20'
231
+ - '50'
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  module Torasup
4
4
  describe Operator do
@@ -11,7 +11,7 @@ module Torasup
11
11
  it "should return the operators with their metadata" do
12
12
  operators = Operator.send(method)
13
13
  operators = Operator.send(method) # run it twice to highlight the duplication problem
14
- with_operators do |number_parts, assertions|
14
+ with_operators do |_number_parts, assertions|
15
15
  operator = operators[assertions["country_id"]][assertions["id"]]
16
16
  expect(operator["country_id"]).to eq(assertions["country_id"])
17
17
  expect(operator["id"]).to eq(assertions["id"])
@@ -53,7 +53,7 @@ module Torasup
53
53
  let(:method) { :registered }
54
54
 
55
55
  def with_operators(&block)
56
- super(:only_registered => {sample_operator[0] => [sample_operator[1]]}, &block)
56
+ super(only_registered: { sample_operator[0] => [sample_operator[1]] }, &block)
57
57
  end
58
58
  end
59
59
  end
@@ -65,10 +65,10 @@ module Torasup
65
65
  subject = Operator.new(*number_parts)
66
66
  assertions.each do |method, assertion|
67
67
  args = []
68
- args << {:interpolation => nil} unless subject.respond_to?(method)
68
+ args << { interpolation: nil } unless subject.respond_to?(method)
69
69
  result = subject.send(method, *args)
70
70
  result_error = result.nil? ? "nil" : "'#{result}'"
71
- expect(result).to(eq(interpolated_assertion(assertion, :interpolation => nil)), "expected Operator.new('#{number_parts}').#{method} to return '#{assertion}' but got #{result_error}")
71
+ expect(result).to(eq(interpolated_assertion(assertion, interpolation: nil)), "expected Operator.new('#{number_parts}').#{method} to return '#{assertion}' but got #{result_error}")
72
72
  end
73
73
  end
74
74
  end
@@ -87,14 +87,25 @@ module Torasup
87
87
 
88
88
  context "with a single configuration file" do
89
89
  let(:configuration_options) { {} }
90
+ let(:options) { { with_custom_pstn_data: true } }
90
91
 
91
- it_should_behave_like "an operator" do
92
- let(:options) { { :with_custom_pstn_data => true } }
92
+ it_should_behave_like "an operator"
93
+
94
+ it "handles default prefixes" do
95
+ torasup_number = Torasup::PhoneNumber.new("5582999489999")
96
+ operator = torasup_number.operator
97
+ expect(operator.id).to eq("mundivox")
98
+ end
99
+
100
+ it "handles long prefixes" do
101
+ torasup_number = Torasup::PhoneNumber.new("919560234567")
102
+ operator = torasup_number.operator
103
+ expect(operator.id).to eq("imimobile")
93
104
  end
94
105
  end
95
106
 
96
107
  context "with multiple configuration files" do
97
- let(:configuration_options) { {:multiple_files => true} }
108
+ let(:configuration_options) { { multiple_files: true } }
98
109
 
99
110
  def assert_overridden_data!
100
111
  torasup_number = Torasup::PhoneNumber.new("85515234567")
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Torasup do
4
4
  describe "#prefixes" do
@@ -6,7 +6,7 @@ describe Torasup do
6
6
 
7
7
  context "metadata" do
8
8
  it "should include the correct min, max and pattern values" do
9
- with_operators do |number_parts, assertions|
9
+ with_operators do |_number_parts, assertions|
10
10
  prefix = assertions["country_code"].to_s + assertions["area_code"].to_s + assertions["prefix"].to_s
11
11
  prefix_metadata = prefixes[prefix]
12
12
  local_number = assertions["local_number"]
@@ -1,27 +1,29 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
1
+
2
+ lib = File.expand_path("lib", __dir__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'torasup/version'
4
+ require "torasup/version"
5
5
 
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "torasup"
8
8
  gem.version = Torasup::VERSION
9
9
  gem.authors = ["David Wilkie"]
10
10
  gem.email = ["dwilkie@gmail.com"]
11
- gem.description = %q{"Retuns metadata about a phone number such as operator, area code and more"}
12
- gem.summary = %q{"Retuns metadata about a phone number such as operator, area code and more"}
11
+ gem.description = '"Retuns metadata about a phone number such as operator, area code and more"'
12
+ gem.summary = '"Retuns metadata about a phone number such as operator, area code and more"'
13
13
  gem.homepage = "https://github.com/dwilkie/torasup/"
14
- gem.license = 'MIT'
14
+ gem.license = "MIT"
15
15
 
16
- gem.files = `git ls-files`.split($/)
17
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- gem.add_runtime_dependency "countries", '>= 1.1.0'
22
- gem.add_runtime_dependency "phony", '>= 2.15.47'
21
+ gem.add_runtime_dependency "countries"
23
22
  gem.add_runtime_dependency "deep_merge"
23
+ gem.add_runtime_dependency "phony"
24
24
 
25
- gem.add_development_dependency "rspec"
25
+ gem.add_development_dependency "codeclimate-test-reporter"
26
26
  gem.add_development_dependency "rake"
27
+ gem.add_development_dependency "rspec"
28
+ gem.add_development_dependency "simplecov"
27
29
  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.1.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Wilkie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-17 00:00:00.000000000 Z
11
+ date: 2020-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: countries
@@ -16,30 +16,30 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.1.0
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
- version: 1.1.0
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: phony
28
+ name: deep_merge
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 2.15.47
33
+ version: '0'
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: 2.15.47
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: deep_merge
42
+ name: phony
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec
56
+ name: codeclimate-test-reporter
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
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'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  description: '"Retuns metadata about a phone number such as operator, area code and
84
112
  more"'
85
113
  email:
@@ -88,9 +116,11 @@ executables: []
88
116
  extensions: []
89
117
  extra_rdoc_files: []
90
118
  files:
119
+ - ".github/workflows/build.yml"
91
120
  - ".gitignore"
92
121
  - ".rspec"
93
- - ".travis.yml"
122
+ - ".rubocop.yml"
123
+ - ".tool-versions"
94
124
  - Gemfile
95
125
  - LICENSE.txt
96
126
  - README.md
@@ -134,8 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
164
  - !ruby/object:Gem::Version
135
165
  version: '0'
136
166
  requirements: []
137
- rubyforge_project:
138
- rubygems_version: 2.6.11
167
+ rubygems_version: 3.1.2
139
168
  signing_key:
140
169
  specification_version: 4
141
170
  summary: '"Retuns metadata about a phone number such as operator, area code and more"'
@@ -1,2 +0,0 @@
1
- rvm:
2
- - 2.3.3