mini_phone 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -7
- data/ext/mini_phone/mini_phone.cc +50 -40
- data/lib/mini_phone/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8267c89cf237c4baf3e8dfe8718e0c0fe453b4919f6e38d00dc70cc557ed8cf0
|
4
|
+
data.tar.gz: 2b537745421bbb9fe70000c3707c6f20c052f0770fd156ac4d915bb92e33c736
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0db1af779c2b9564dedc09eee290359b5d3bb53bfb8e53180b1d56225cd054d1bddc37b87ff7da794cc2686c04ccbfcaed0285cebea170e4f5b5f594ee841091
|
7
|
+
data.tar.gz: 9e94872e27a229014cc754fe349e5d9f536baef87e26aee5b6bd9205604c553fcd392fa8ec4c658f9e5fedb0f958217e3b839337559200cded15b36442f2ab45
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
A Ruby gem which plugs directly into Google's native C++
|
4
4
|
[libphonenumber](https://github.com/google/libphonenumber) for extremely
|
5
5
|
_fast_ and _robust_ phone number parsing, validation, and formatting. On
|
6
|
-
average, most methods are
|
6
|
+
average, most methods are 70x to 80x faster than other Ruby phone number
|
7
7
|
libraries.
|
8
8
|
|
9
9
|
## Usage
|
@@ -78,15 +78,15 @@ On average, most methods are 40x to 50x faster than other libraries. To run
|
|
78
78
|
the benchmarks locally, execute: `bundle exec rake bench`
|
79
79
|
|
80
80
|
```
|
81
|
+
# Results from my Linux (5.10.6-arch1-10)
|
82
|
+
|
81
83
|
Comparison:
|
82
|
-
|
83
|
-
|
84
|
-
```
|
84
|
+
Phonelib: valid?: 426.0 i/s
|
85
|
+
MiniPhone: valid?: 34707.9 i/s - 81.47x faster
|
85
86
|
|
86
|
-
```
|
87
87
|
Comparison:
|
88
|
-
|
89
|
-
|
88
|
+
Phonelib: e164: 580.3 i/s
|
89
|
+
MiniPhone: e164: 43385.9 i/s - 74.76x faster
|
90
90
|
```
|
91
91
|
|
92
92
|
## Installation
|
@@ -52,7 +52,13 @@ static inline VALUE is_phone_number_valid(VALUE self, VALUE str, VALUE cc) {
|
|
52
52
|
|
53
53
|
auto result = phone_util.ParseAndKeepRawInput(phone_number, country_code, &parsed_number);
|
54
54
|
|
55
|
-
if (result
|
55
|
+
if (result != PhoneNumberUtil::NO_PARSING_ERROR) {
|
56
|
+
return Qfalse;
|
57
|
+
}
|
58
|
+
|
59
|
+
if (country_code == "ZZ" && phone_util.IsValidNumber(parsed_number)) {
|
60
|
+
return Qtrue;
|
61
|
+
} else if (phone_util.IsValidNumberForRegion(parsed_number, country_code)) {
|
56
62
|
return Qtrue;
|
57
63
|
} else {
|
58
64
|
return Qfalse;
|
@@ -159,45 +165,6 @@ static inline VALUE rb_phone_number_nullify_ivars(VALUE self) {
|
|
159
165
|
return Qtrue;
|
160
166
|
}
|
161
167
|
|
162
|
-
extern "C" VALUE rb_phone_number_initialize(int argc, VALUE *argv, VALUE self) {
|
163
|
-
VALUE str;
|
164
|
-
VALUE def_cc;
|
165
|
-
|
166
|
-
rb_scan_args(argc, argv, "11", &str, &def_cc);
|
167
|
-
|
168
|
-
if (NIL_P(def_cc)) {
|
169
|
-
def_cc = rb_iv_get(rb_mMiniPhone, "@default_country");
|
170
|
-
}
|
171
|
-
|
172
|
-
rb_iv_set(self, "@input", str);
|
173
|
-
|
174
|
-
if (FIXNUM_P(str)) {
|
175
|
-
str = rb_fix2str(str, 10);
|
176
|
-
} else if (!RB_TYPE_P(str, T_STRING)) {
|
177
|
-
return rb_phone_number_nullify_ivars(self);
|
178
|
-
}
|
179
|
-
|
180
|
-
PhoneNumberInfo *phone_number_info;
|
181
|
-
PhoneNumber parsed_number;
|
182
|
-
|
183
|
-
TypedData_Get_Struct(self, PhoneNumberInfo, &phone_number_info_type, phone_number_info);
|
184
|
-
|
185
|
-
const PhoneNumberUtil &phone_util(*PhoneNumberUtil::GetInstance());
|
186
|
-
|
187
|
-
std::string phone_number(RSTRING_PTR(str), RSTRING_LEN(str));
|
188
|
-
std::string country_code(RSTRING_PTR(def_cc), RSTRING_LEN(def_cc));
|
189
|
-
|
190
|
-
auto result = phone_util.Parse(phone_number, country_code, &parsed_number);
|
191
|
-
|
192
|
-
if (result != PhoneNumberUtil::NO_PARSING_ERROR) {
|
193
|
-
rb_phone_number_nullify_ivars(self);
|
194
|
-
} else {
|
195
|
-
phone_number_info->phone_number->Swap(&parsed_number);
|
196
|
-
}
|
197
|
-
|
198
|
-
return self;
|
199
|
-
}
|
200
|
-
|
201
168
|
static inline VALUE rb_phone_number_format(VALUE self, PhoneNumberUtil::PhoneNumberFormat fmt) {
|
202
169
|
std::string formatted_number;
|
203
170
|
PhoneNumberInfo *phone_number_info;
|
@@ -502,6 +469,49 @@ static inline void setup_formats() {
|
|
502
469
|
dsh_fmt->set_format("$1-$2-$3");
|
503
470
|
}
|
504
471
|
|
472
|
+
extern "C" VALUE rb_phone_number_initialize(int argc, VALUE *argv, VALUE self) {
|
473
|
+
VALUE str;
|
474
|
+
VALUE def_cc;
|
475
|
+
|
476
|
+
rb_scan_args(argc, argv, "11", &str, &def_cc);
|
477
|
+
|
478
|
+
if (NIL_P(def_cc)) {
|
479
|
+
def_cc = rb_iv_get(rb_mMiniPhone, "@default_country");
|
480
|
+
}
|
481
|
+
|
482
|
+
rb_iv_set(self, "@input", str);
|
483
|
+
|
484
|
+
if (FIXNUM_P(str)) {
|
485
|
+
str = rb_fix2str(str, 10);
|
486
|
+
} else if (!RB_TYPE_P(str, T_STRING)) {
|
487
|
+
return rb_phone_number_nullify_ivars(self);
|
488
|
+
}
|
489
|
+
|
490
|
+
PhoneNumberInfo *phone_number_info;
|
491
|
+
PhoneNumber parsed_number;
|
492
|
+
|
493
|
+
TypedData_Get_Struct(self, PhoneNumberInfo, &phone_number_info_type, phone_number_info);
|
494
|
+
|
495
|
+
const PhoneNumberUtil &phone_util(*PhoneNumberUtil::GetInstance());
|
496
|
+
|
497
|
+
std::string phone_number(RSTRING_PTR(str), RSTRING_LEN(str));
|
498
|
+
std::string country_code(RSTRING_PTR(def_cc), RSTRING_LEN(def_cc));
|
499
|
+
|
500
|
+
auto result = phone_util.Parse(phone_number, country_code, &parsed_number);
|
501
|
+
|
502
|
+
if (result != PhoneNumberUtil::NO_PARSING_ERROR) {
|
503
|
+
rb_phone_number_nullify_ivars(self);
|
504
|
+
} else {
|
505
|
+
phone_number_info->phone_number->Swap(&parsed_number);
|
506
|
+
}
|
507
|
+
|
508
|
+
if (country_code != "ZZ" && !rb_str_equal(rb_phone_number_region_code(self), def_cc)) {
|
509
|
+
rb_phone_number_nullify_ivars(self);
|
510
|
+
}
|
511
|
+
|
512
|
+
return self;
|
513
|
+
}
|
514
|
+
|
505
515
|
extern "C" void Init_mini_phone(void) {
|
506
516
|
setup_formats();
|
507
517
|
|
data/lib/mini_phone/version.rb
CHANGED
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: 1.1.
|
4
|
+
version: 1.1.4
|
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-
|
11
|
+
date: 2021-02-11 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.
|