mini_phone 0.1.7 → 1.0.3

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
  SHA256:
3
- metadata.gz: d7bb347a05cfd2252b4d3da6bfb2918ab277ac8c0ade0d1ebfc1bd14d95a7acd
4
- data.tar.gz: d62bb44c21e637a343f039df50bd12f196ab27b763f426a635c080ac08e549a1
3
+ metadata.gz: 8f19ec27523bfdcd42b72b4421441b4016b4bf86c94f91f527e10bf5a33d1a16
4
+ data.tar.gz: 7ab2cf83930eaa1c35f7bf2a2faa7afded85238b8a69bf8822013f3f33ee274a
5
5
  SHA512:
6
- metadata.gz: 321ffa3218cb9d040b40d8ec8b03281ae1d92e910ab66275b21f258183f6e17fd14bfaa5a8629401cf3aae5b059727a6182ebff366d10badcbd8376eca908789
7
- data.tar.gz: 7916ba4ee31c8f9414481dbad9d4210d5fd16f4e77372588e1bf7154eb12f4d47d53dac1c413e905567abddd6e18284c386bda40bee0feb6ca5b617a2266f8ea
6
+ metadata.gz: 853cc1202032f2c6f2fec744de57bfdabac907116fd1495060b65c5d51da060dbf317f253ca3179787f2de9162c7961e83d3f1c39909bbf7ae252262dcfaf7e4
7
+ data.tar.gz: 3965cf5f9798b3529eab55f0eb24b3532950f306005fca4655589d8d27c925028115a976fa623af6ca16e715aa6f8f9993cd8716779356f5c194b7cc5f7d4e6f
data/Gemfile CHANGED
@@ -5,11 +5,12 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in mini_phone.gemspec
6
6
  gemspec
7
7
 
8
- gem 'rake', '~> 12.0'
8
+ gem 'rake', require: false
9
+ # https://github.com/rake-compiler/rake-compiler/pull/166
9
10
  gem 'rake-compiler', github: 'larskanis/rake-compiler', branch: 'fix-native-version'
10
- gem 'rspec', '~> 3.0'
11
+ gem 'rspec', '~> 3.0', require: false
11
12
  gem 'rspec-github', require: false
12
- gem 'rubocop'
13
+ gem 'rubocop', require: false
13
14
 
14
15
  group :bench do
15
16
  gem 'benchmark-ips'
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ RSpec::Core::RakeTask.new(:spec)
9
9
 
10
10
  task build: :compile
11
11
 
12
- task default: %i[clobber compile spec]
12
+ task default: %i[clobber compile spec lint]
13
13
 
14
14
  spec = Gem::Specification.load(File.expand_path('mini_phone.gemspec', __dir__))
15
15
 
@@ -28,7 +28,11 @@ task bench: %i[clobber compile] do
28
28
  end
29
29
  end
30
30
 
31
- task :deploy do
31
+ task :lint do
32
+ sh 'bundle exec rubocop'
33
+ end
34
+
35
+ task deploy: :default do
32
36
  sh 'code -w ./lib/mini_phone/version.rb'
33
37
  version = `ruby -r ./lib/mini_phone/version.rb -e 'print MiniPhone::VERSION'`.strip
34
38
  sh "git commit -am 'Bump to v#{version} :confetti_ball:'"
@@ -63,11 +67,7 @@ namespace :publish do
63
67
  task non_native: [:gem] do
64
68
  g = "./pkg/mini_phone-#{MiniPhone::VERSION}.gem"
65
69
 
66
- results = []
67
-
68
- results << push_to_rubygems(g)
69
- results << push_to_github_registry(g)
70
-
71
- abort if results.all? { |r| r == true }
70
+ push_to_rubygems(g)
71
+ push_to_github_registry(g)
72
72
  end
73
73
  end
@@ -4,47 +4,6 @@
4
4
 
5
5
  require 'mkmf'
6
6
 
7
- LIBDIR = RbConfig::CONFIG['libdir']
8
-
9
- INCLUDEDIR = RbConfig::CONFIG['includedir']
10
-
11
- header_dirs = [
12
- # First search /opt/local for macports
13
- '/opt/local/include',
14
-
15
- # Then search /usr/local for people that installed from source
16
- '/usr/local/include',
17
-
18
- # Check the ruby install locations
19
- INCLUDEDIR,
20
-
21
- # Finally fall back to /usr
22
- '/usr/include'
23
- ]
24
-
25
- lib_dirs = [
26
- # First search /opt/local for macports
27
- '/opt/local/lib',
28
-
29
- # Then search /usr/local for people that installed from source
30
- '/usr/local/lib',
31
-
32
- # Check the ruby install locations
33
- LIBDIR,
34
-
35
- # Finally fall back to /usr
36
- '/usr/lib'
37
- ]
38
-
39
- # Detect homebrew installs
40
- if find_executable('brew')
41
- brew_prefix = `brew --prefix`.strip
42
- header_dirs.unshift "#{brew_prefix}/include"
43
- lib_dirs.unshift "#{brew_prefix}/lib"
44
- end
45
-
46
- dir_config('mini_phone', header_dirs, lib_dirs)
47
-
48
7
  unless have_library('phonenumber')
49
8
  abort <<~MSG
50
9
 
@@ -70,7 +29,9 @@ unless have_library('phonenumber')
70
29
  MSG
71
30
  end
72
31
 
73
- $CXXFLAGS += ' -std=c++11 '
32
+ dir_config('mini_phone')
33
+
34
+ $CXXFLAGS += ' -std=c++11 -ofast '
74
35
 
75
36
  create_makefile('mini_phone/mini_phone')
76
37
 
@@ -1,12 +1,18 @@
1
1
  #include "mini_phone.h"
2
+ #include "phonenumbers/phonemetadata.pb.h"
3
+ #include "phonenumbers/phonenumber.pb.h"
2
4
  #include "phonenumbers/phonenumberutil.h"
3
5
 
4
6
  using namespace ::i18n::phonenumbers;
5
7
 
8
+ using google::protobuf::RepeatedPtrField;
9
+
6
10
  static VALUE rb_mMiniPhone;
7
11
 
8
12
  static VALUE rb_cPhoneNumber;
9
13
 
14
+ static RepeatedPtrField<NumberFormat> raw_national_format;
15
+
10
16
  extern "C" struct PhoneNumberInfo {
11
17
  PhoneNumber phone_number;
12
18
  std::string raw_phone_number;
@@ -30,7 +36,7 @@ static inline VALUE is_phone_number_valid(VALUE self, VALUE str, VALUE cc) {
30
36
  }
31
37
 
32
38
  extern "C" VALUE rb_is_phone_number_valid(VALUE self, VALUE str) {
33
- VALUE def_cc = rb_iv_get(rb_mMiniPhone, "@default_country_code");
39
+ VALUE def_cc = rb_iv_get(rb_mMiniPhone, "@default_country");
34
40
 
35
41
  return is_phone_number_valid(self, str, def_cc);
36
42
  }
@@ -51,7 +57,7 @@ extern "C" VALUE rb_is_phone_number_possible(VALUE self, VALUE str) {
51
57
  PhoneNumber parsed_number;
52
58
  PhoneNumberUtil *phone_util = PhoneNumberUtil::GetInstance();
53
59
 
54
- VALUE def_cc = rb_iv_get(rb_mMiniPhone, "@default_country_code");
60
+ VALUE def_cc = rb_iv_get(rb_mMiniPhone, "@default_country");
55
61
  std::string phone_number(RSTRING_PTR(str), RSTRING_LEN(str));
56
62
  std::string country_code(RSTRING_PTR(def_cc), RSTRING_LEN(def_cc));
57
63
 
@@ -68,11 +74,11 @@ extern "C" VALUE rb_is_phone_number_impossible(VALUE self, VALUE str) {
68
74
  return rb_is_phone_number_possible(self, str) == Qtrue ? Qfalse : Qtrue;
69
75
  }
70
76
 
71
- extern "C" VALUE rb_set_default_country_code(VALUE self, VALUE str_code) {
72
- return rb_iv_set(self, "@default_country_code", str_code);
77
+ extern "C" VALUE rb_set_default_country(VALUE self, VALUE str_code) {
78
+ return rb_iv_set(self, "@default_country", str_code);
73
79
  }
74
80
 
75
- extern "C" VALUE rb_get_default_country_code(VALUE self) { return rb_iv_get(self, "@default_country_code"); }
81
+ extern "C" VALUE rb_get_default_country(VALUE self) { return rb_iv_get(self, "@default_country"); }
76
82
 
77
83
  extern "C" void rb_phone_number_dealloc(PhoneNumberInfo *phone_number_info) { delete phone_number_info; }
78
84
 
@@ -89,6 +95,7 @@ extern "C" VALUE rb_phone_number_alloc(VALUE self) {
89
95
 
90
96
  static inline VALUE rb_phone_number_nullify_ivars(VALUE self) {
91
97
  rb_iv_set(self, "@national", Qnil);
98
+ rb_iv_set(self, "@raw_national", Qnil);
92
99
  rb_iv_set(self, "@international", Qnil);
93
100
  rb_iv_set(self, "@e164", Qnil);
94
101
  rb_iv_set(self, "@country_code", Qnil);
@@ -108,7 +115,7 @@ extern "C" VALUE rb_phone_number_initialize(int argc, VALUE *argv, VALUE self) {
108
115
  rb_scan_args(argc, argv, "11", &str, &def_cc);
109
116
 
110
117
  if (NIL_P(def_cc)) {
111
- def_cc = rb_iv_get(rb_mMiniPhone, "@default_country_code");
118
+ def_cc = rb_iv_get(rb_mMiniPhone, "@default_country");
112
119
  }
113
120
 
114
121
  rb_iv_set(self, "@input", str);
@@ -185,6 +192,24 @@ extern "C" VALUE rb_phone_number_rfc3966(VALUE self) {
185
192
  return rb_iv_set(self, "@rfc3966", rb_phone_number_format(self, PhoneNumberUtil::PhoneNumberFormat::RFC3966));
186
193
  }
187
194
 
195
+ extern "C" VALUE rb_phone_number_raw_national(VALUE self) {
196
+ if (rb_ivar_defined(self, rb_intern("@raw_national"))) {
197
+ return rb_iv_get(self, "@raw_national");
198
+ }
199
+
200
+ std::string formatted_number;
201
+ PhoneNumberInfo *phone_number_info;
202
+ PhoneNumberUtil *phone_util = PhoneNumberUtil::GetInstance();
203
+ Data_Get_Struct(self, PhoneNumberInfo, phone_number_info);
204
+
205
+ phone_util->FormatByPattern(phone_number_info->phone_number, PhoneNumberUtil::NATIONAL, raw_national_format,
206
+ &formatted_number);
207
+
208
+ VALUE result = rb_str_new(formatted_number.c_str(), formatted_number.size());
209
+
210
+ return rb_iv_set(self, "@raw_national", result);
211
+ }
212
+
188
213
  extern "C" VALUE rb_phone_number_valid_eh(VALUE self) {
189
214
  if (rb_ivar_defined(self, rb_intern("@valid"))) {
190
215
  return rb_iv_get(self, "@valid");
@@ -339,7 +364,7 @@ extern "C" void Init_mini_phone(void) {
339
364
  rb_mMiniPhone = rb_define_module("MiniPhone");
340
365
 
341
366
  // Unknown
342
- rb_iv_set(rb_mMiniPhone, "@default_country_code", rb_str_new("ZZ", 2));
367
+ rb_iv_set(rb_mMiniPhone, "@default_country", rb_str_new("ZZ", 2));
343
368
 
344
369
  rb_define_module_function(rb_mMiniPhone, "valid?", reinterpret_cast<VALUE (*)(...)>(rb_is_phone_number_valid), 1);
345
370
  rb_define_module_function(rb_mMiniPhone, "valid_for_country?",
@@ -350,10 +375,10 @@ extern "C" void Init_mini_phone(void) {
350
375
  rb_define_module_function(rb_mMiniPhone, "possible?", reinterpret_cast<VALUE (*)(...)>(rb_is_phone_number_valid), 1);
351
376
  rb_define_module_function(rb_mMiniPhone, "impossible?", reinterpret_cast<VALUE (*)(...)>(rb_is_phone_number_invalid),
352
377
  1);
353
- rb_define_module_function(rb_mMiniPhone,
354
- "default_country_code=", reinterpret_cast<VALUE (*)(...)>(rb_set_default_country_code), 1);
355
- rb_define_module_function(rb_mMiniPhone, "default_country_code",
356
- reinterpret_cast<VALUE (*)(...)>(rb_get_default_country_code), 0);
378
+ rb_define_module_function(rb_mMiniPhone, "default_country=", reinterpret_cast<VALUE (*)(...)>(rb_set_default_country),
379
+ 1);
380
+ rb_define_module_function(rb_mMiniPhone, "default_country", reinterpret_cast<VALUE (*)(...)>(rb_get_default_country),
381
+ 0);
357
382
  rb_define_module_function(rb_mMiniPhone, "parse", reinterpret_cast<VALUE (*)(...)>(rb_phone_number_parse), -1);
358
383
 
359
384
  rb_cPhoneNumber = rb_define_class_under(rb_mMiniPhone, "PhoneNumber", rb_cObject);
@@ -367,6 +392,11 @@ extern "C" void Init_mini_phone(void) {
367
392
  rb_define_method(rb_cPhoneNumber, "impossible?", reinterpret_cast<VALUE (*)(...)>(rb_phone_number_impossible_eh), 0);
368
393
  rb_define_method(rb_cPhoneNumber, "e164", reinterpret_cast<VALUE (*)(...)>(rb_phone_number_e164), 0);
369
394
  rb_define_method(rb_cPhoneNumber, "national", reinterpret_cast<VALUE (*)(...)>(rb_phone_number_national), 0);
395
+
396
+ // Raw National
397
+ raw_national_format.Add()->set_format("$1$2$3");
398
+
399
+ rb_define_method(rb_cPhoneNumber, "raw_national", reinterpret_cast<VALUE (*)(...)>(rb_phone_number_raw_national), 0);
370
400
  rb_define_method(rb_cPhoneNumber, "international", reinterpret_cast<VALUE (*)(...)>(rb_phone_number_international),
371
401
  0);
372
402
  rb_define_method(rb_cPhoneNumber, "rfc3966", reinterpret_cast<VALUE (*)(...)>(rb_phone_number_rfc3966), 0);
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MiniPhone
4
- VERSION = '0.1.7'
4
+ VERSION = '1.0.3'
5
5
  end
@@ -27,7 +27,10 @@ Gem::Specification.new do |spec|
27
27
  # Specify which files should be added to the gem when it is released.
28
28
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
29
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
30
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(bin|spec|bench)/}) }
30
+ `git ls-files -z`
31
+ .split("\x0")
32
+ .reject { |f| f.match(%r{^(bin|spec|bench)/}) }
33
+ .reject { |f| f.start_with?('.') }
31
34
  end
32
35
  spec.bindir = 'exe'
33
36
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_phone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Ker-Seymer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-05 00:00:00.000000000 Z
11
+ date: 2021-01-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Plugs directly in the the Google's native C++ [libphonenumber](https://github.com/google/libphonenumber)
14
14
  for extemely _fast_ and _robust_ phone number parsing, validation, and formatting.
@@ -20,13 +20,6 @@ extensions:
20
20
  - ext/mini_phone/extconf.rb
21
21
  extra_rdoc_files: []
22
22
  files:
23
- - ".clang-format"
24
- - ".github/workflows/ci.yml"
25
- - ".github/workflows/release.yml"
26
- - ".gitignore"
27
- - ".rspec"
28
- - ".rubocop.yml"
29
- - ".travis.yml"
30
23
  - CHANGELOG.md
31
24
  - CODE_OF_CONDUCT.md
32
25
  - Gemfile
@@ -1,3 +0,0 @@
1
- ---
2
- BasedOnStyle: LLVM
3
- ColumnLimit: 120
@@ -1,51 +0,0 @@
1
- ---
2
- name: CI
3
-
4
- on: push
5
-
6
- jobs:
7
- build:
8
- strategy:
9
- fail-fast: false
10
- matrix:
11
- ruby: ["2.5", "2.6", "2.7"]
12
- os: [ubuntu-latest, macos-latest]
13
- experimental: [false]
14
- # include:
15
- # - ruby: "truffleruby"
16
- # os: ubuntu-latest
17
- # experimental: true
18
- # - ruby: "truffleruby"
19
- # os: macos-latest
20
- # experimental: true
21
- name: ${{ matrix.ruby }} on ${{ matrix.os }}
22
- runs-on: ${{ matrix.os }}
23
- continue-on-error: ${{ matrix.experimental }}
24
- env:
25
- CI_EXPERIMENTAL: ${{ matrix.experimental }}
26
- steps:
27
- - uses: actions/checkout@v2
28
-
29
- - uses: ruby/setup-ruby@v1
30
- with:
31
- ruby-version: ${{ matrix.ruby }}
32
-
33
- - name: Install dependencies (system)
34
- if: ${{ matrix.os == 'ubuntu-latest' }}
35
- run: sudo apt-get -yqq install libphonenumber-dev
36
-
37
- - name: Install dependencies (system)
38
- if: ${{ matrix.os == 'macos-latest' }}
39
- run: brew install --build-from-source libphonenumber && brew link libphonenumber
40
-
41
- - name: Install dependencies (ruby)
42
- run: gem install bundler && bundle install --jobs 4 --retry 3
43
-
44
- - name: Compile
45
- run: bundle exec rake compile
46
-
47
- - name: RSpec
48
- run: bundle exec rspec --format RSpec::Github::Formatter --format documentation
49
-
50
- - name: Rubocop
51
- run: bundle exec rubocop --format github
@@ -1,55 +0,0 @@
1
- ---
2
- name: Release
3
-
4
- on:
5
- push:
6
- tags:
7
- - "v*"
8
-
9
- jobs:
10
- build:
11
- strategy:
12
- fail-fast: false
13
- matrix:
14
- ruby: ["2.7"]
15
- os: [ubuntu-latest, macos-latest]
16
- name: ${{ matrix.os }}
17
- runs-on: ${{ matrix.os }}
18
- steps:
19
- - uses: actions/checkout@v2
20
-
21
- - uses: ruby/setup-ruby@v1
22
- with:
23
- ruby-version: ${{ matrix.ruby }}
24
-
25
- - name: Install dependencies (system)
26
- if: ${{ matrix.os == 'ubuntu-latest' }}
27
- run: sudo apt-get -yqq install libphonenumber-dev
28
-
29
- - name: Install dependencies (system)
30
- if: ${{ matrix.os == 'macos-latest' }}
31
- run: brew install --build-from-source libphonenumber && brew link libphonenumber
32
-
33
- - name: Install dependencies (ruby)
34
- run: gem install bundler && bundle install --jobs 4 --retry 3
35
-
36
- - name: Login
37
- run: |
38
- mkdir -p ~/.gem
39
-
40
- cat << EOF > ~/.gem/credentials
41
- ---
42
- :github: ${GITHUB_AUTH_TOKEN}
43
- :rubygems_api_key: ${RUBYGEMS_AUTH_TOKEN}
44
- EOF
45
-
46
- chmod 0600 ~/.gem/credentials
47
- env:
48
- GITHUB_AUTH_TOKEN: "Bearer ${{secrets.GITHUB_TOKEN}}"
49
- RUBYGEMS_AUTH_TOKEN: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
50
- OWNER: ${{ github.repository_owner }}
51
-
52
- - name: 🛳 Ship it
53
- run: |
54
- bundle exec rake publish:native
55
- bundle exec rake publish:non_native || true
data/.gitignore DELETED
@@ -1,19 +0,0 @@
1
- .bundle/
2
- .yardoc
3
- _yardoc/
4
- coverage/
5
- doc/
6
- pkg/
7
- spec/reports/
8
- tmp/
9
- *.bundle
10
- *.so
11
- *.o
12
- *.a
13
- mkmf.log
14
-
15
- # rspec failure tracking
16
- .rspec_status
17
- Gemfile.lock
18
- vendor/cache/
19
- *.gem
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
@@ -1,23 +0,0 @@
1
- # The behavior of RuboCop can be controlled via the .rubocop.yml
2
- # configuration file. It makes it possible to enable/disable
3
- # certain cops (checks) and to alter their behavior if they accept
4
- # any parameters. The file can be placed either in your home
5
- # directory or in some project directory.
6
- #
7
- # RuboCop will start looking for the configuration file in the directory
8
- # where the inspected file is and continue its way up to the root directory.
9
- #
10
- # See https://docs.rubocop.org/rubocop/configuration
11
- AllCops:
12
- TargetRubyVersion: 2.5
13
- NewCops: enable
14
- SuggestExtensions: false
15
- Exclude:
16
- - pkg/**/*
17
- - tmp/**/*
18
-
19
- Metrics/BlockLength:
20
- Exclude:
21
- - spec/**/*
22
- - Rakefile
23
- - Gemfile
@@ -1,6 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.7.1
6
- before_install: gem install bundler -v 2.1.4