mini_phone 1.0.4 → 1.0.5
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 +4 -4
- data/README.md +17 -15
- data/ext/mini_phone/mini_phone.cc +39 -11
- 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: e442f98e547a4059112a40d4a28d79b7438ded4ec9d697ed7a59e03447e073f3
|
4
|
+
data.tar.gz: b7ff1d3b6c32564197471098acb0654f214a035df703382500a5c7c825b80d9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90e2db831e7edf8ccbe083f3daad5830d8d65d6945598441a4b7bc38c0b191d5aec85c7356b9549375add822e3e6b8d27d550ed647d1721d29fb4113e50e6fc3
|
7
|
+
data.tar.gz: adc1643314e3f781e9c427ff6540ba406995c14e9429fa4c520b681375459a73711fa1cbf8072c51c7f2b79f781a44fd81d219e79c6388e0d6c25f3e56e0e781
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# MiniPhone
|
2
2
|
|
3
|
-
A Ruby gem which plugs directly
|
4
|
-
[libphonenumber](https://github.com/google/libphonenumber) for
|
3
|
+
A Ruby gem which plugs directly into Google's native C++
|
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 40x
|
6
|
+
average, most methods are 40x to 50x faster than other Ruby phone number
|
7
7
|
libraries.
|
8
8
|
|
9
9
|
## Usage
|
@@ -23,10 +23,12 @@ MiniPhone.default_country = 'US'
|
|
23
23
|
|
24
24
|
phone_number = MiniPhone.parse('404-384-1399')
|
25
25
|
|
26
|
-
phone_number.e164
|
27
|
-
phone_number.national
|
28
|
-
phone_number.
|
29
|
-
phone_number.
|
26
|
+
phone_number.e164 # +14043841399
|
27
|
+
phone_number.national # (404) 384-1399
|
28
|
+
phone_number.raw_national # 4043841399
|
29
|
+
phone_number.dasherized_national # 404-384-1399
|
30
|
+
phone_number.international # +1 404-384-1399
|
31
|
+
phone_number.rfc3966 # tel:+1-404-384-1384
|
30
32
|
```
|
31
33
|
|
32
34
|
### Checking if a phone number is possible
|
@@ -41,7 +43,7 @@ phone_number.possible? # false
|
|
41
43
|
|
42
44
|
```ruby
|
43
45
|
MiniPhone.parse('+12423570000').type # :mobile
|
44
|
-
MiniPhone.parse
|
46
|
+
MiniPhone.parse('+12423651234').type # :fixed_line
|
45
47
|
```
|
46
48
|
|
47
49
|
The possible types are directly mapped from [this
|
@@ -65,14 +67,14 @@ enum](https://github.com/google/libphonenumber/blob/4e9954edea7cf263532c5dd3861a
|
|
65
67
|
## Compatibility with PhoneLib
|
66
68
|
|
67
69
|
MiniPhone aims to be compatible with
|
68
|
-
[Phonelib](https://github.com/daddyz/phonelib)
|
69
|
-
drop in replacement. It has a smaller feature set, so
|
70
|
-
|
70
|
+
[Phonelib](https://github.com/daddyz/phonelib). In many cases it can be a
|
71
|
+
drop in replacement. It has a smaller feature set, so it is not a
|
72
|
+
replacement for every use case. If there is a feature you need, open
|
71
73
|
an issue and we will try to support it.
|
72
74
|
|
73
75
|
## Benchmarks
|
74
76
|
|
75
|
-
On average, most methods are 40x
|
77
|
+
On average, most methods are 40x to 50x faster than other libraries. To run
|
76
78
|
the benchmarks locally, execute: `bundle exec rake bench`
|
77
79
|
|
78
80
|
```
|
@@ -132,10 +134,10 @@ push git commits and tags, and push the `.gem` file to
|
|
132
134
|
## Contributing
|
133
135
|
|
134
136
|
Bug reports and pull requests are welcome on GitHub at
|
135
|
-
https://github.com/
|
137
|
+
https://github.com/ianks/mini_phone. This project is intended to be a
|
136
138
|
safe, welcoming space for collaboration, and contributors are expected to
|
137
139
|
adhere to the [code of
|
138
|
-
conduct](https://github.com/
|
140
|
+
conduct](https://github.com/ianks/mini_phone/blob/master/CODE_OF_CONDUCT.md).
|
139
141
|
|
140
142
|
## License
|
141
143
|
|
@@ -146,4 +148,4 @@ License](https://opensource.org/licenses/MIT).
|
|
146
148
|
|
147
149
|
Everyone interacting in the MiniPhone project's codebases, issue trackers,
|
148
150
|
chat rooms and mailing lists is expected to follow the [code of
|
149
|
-
conduct](https://github.com/
|
151
|
+
conduct](https://github.com/ianks/mini_phone/blob/master/CODE_OF_CONDUCT.md).
|
@@ -12,6 +12,7 @@ static VALUE rb_mMiniPhone;
|
|
12
12
|
static VALUE rb_cPhoneNumber;
|
13
13
|
|
14
14
|
static RepeatedPtrField<NumberFormat> raw_national_format;
|
15
|
+
static RepeatedPtrField<NumberFormat> dasherized_national_format;
|
15
16
|
|
16
17
|
extern "C" struct PhoneNumberInfo {
|
17
18
|
PhoneNumber phone_number;
|
@@ -122,6 +123,7 @@ extern "C" VALUE rb_phone_number_alloc(VALUE self) {
|
|
122
123
|
static inline VALUE rb_phone_number_nullify_ivars(VALUE self) {
|
123
124
|
rb_iv_set(self, "@national", Qnil);
|
124
125
|
rb_iv_set(self, "@raw_national", Qnil);
|
126
|
+
rb_iv_set(self, "@dasherized_national", Qnil);
|
125
127
|
rb_iv_set(self, "@international", Qnil);
|
126
128
|
rb_iv_set(self, "@e164", Qnil);
|
127
129
|
rb_iv_set(self, "@country_code", Qnil);
|
@@ -219,24 +221,37 @@ extern "C" VALUE rb_phone_number_rfc3966(VALUE self) {
|
|
219
221
|
return rb_iv_set(self, "@rfc3966", rb_phone_number_format(self, PhoneNumberUtil::PhoneNumberFormat::RFC3966));
|
220
222
|
}
|
221
223
|
|
222
|
-
|
223
|
-
if (rb_ivar_defined(self, rb_intern("@raw_national"))) {
|
224
|
-
return rb_iv_get(self, "@raw_national");
|
225
|
-
}
|
226
|
-
|
224
|
+
VALUE format_by_pattern_national(VALUE self, RepeatedPtrField<NumberFormat> format) {
|
227
225
|
std::string formatted_number;
|
228
226
|
PhoneNumberInfo *phone_number_info;
|
229
227
|
const PhoneNumberUtil &phone_util(*PhoneNumberUtil::GetInstance());
|
230
228
|
Data_Get_Struct(self, PhoneNumberInfo, phone_number_info);
|
231
229
|
|
232
|
-
phone_util.FormatByPattern(phone_number_info->phone_number, PhoneNumberUtil::NATIONAL,
|
233
|
-
|
230
|
+
phone_util.FormatByPattern(phone_number_info->phone_number, PhoneNumberUtil::NATIONAL, format, &formatted_number);
|
231
|
+
|
232
|
+
return rb_str_new(formatted_number.c_str(), formatted_number.size());
|
233
|
+
}
|
234
234
|
|
235
|
-
|
235
|
+
extern "C" VALUE rb_phone_number_raw_national(VALUE self) {
|
236
|
+
if (rb_ivar_defined(self, rb_intern("@raw_national"))) {
|
237
|
+
return rb_iv_get(self, "@raw_national");
|
238
|
+
}
|
239
|
+
|
240
|
+
VALUE result = format_by_pattern_national(self, raw_national_format);
|
236
241
|
|
237
242
|
return rb_iv_set(self, "@raw_national", result);
|
238
243
|
}
|
239
244
|
|
245
|
+
extern "C" VALUE rb_phone_number_dasherized_national(VALUE self) {
|
246
|
+
if (rb_ivar_defined(self, rb_intern("@dasherized_national"))) {
|
247
|
+
return rb_iv_get(self, "@dasherized_national");
|
248
|
+
}
|
249
|
+
|
250
|
+
VALUE result = format_by_pattern_national(self, dasherized_national_format);
|
251
|
+
|
252
|
+
return rb_iv_set(self, "@dasherized_national", result);
|
253
|
+
}
|
254
|
+
|
240
255
|
extern "C" VALUE rb_phone_number_valid_eh(VALUE self) {
|
241
256
|
if (rb_ivar_defined(self, rb_intern("@valid"))) {
|
242
257
|
return rb_iv_get(self, "@valid");
|
@@ -416,7 +431,21 @@ extern "C" VALUE rb_phone_number_area_code(VALUE self) {
|
|
416
431
|
return rb_iv_set(self, "@area_code", result);
|
417
432
|
}
|
418
433
|
|
434
|
+
static inline void setup_formats() {
|
435
|
+
// Raw
|
436
|
+
NumberFormat *raw_fmt = raw_national_format.Add();
|
437
|
+
raw_fmt->set_pattern("(\\d{3})(\\d{3})(\\d{4})");
|
438
|
+
raw_fmt->set_format("$1$2$3");
|
439
|
+
|
440
|
+
// Dasherized
|
441
|
+
NumberFormat *dsh_fmt = dasherized_national_format.Add();
|
442
|
+
dsh_fmt->set_pattern("(\\d{3})(\\d{3})(\\d{4})");
|
443
|
+
dsh_fmt->set_format("$1-$2-$3");
|
444
|
+
}
|
445
|
+
|
419
446
|
extern "C" void Init_mini_phone(void) {
|
447
|
+
setup_formats();
|
448
|
+
|
420
449
|
rb_mMiniPhone = rb_define_module("MiniPhone");
|
421
450
|
|
422
451
|
// Unknown
|
@@ -451,10 +480,9 @@ extern "C" void Init_mini_phone(void) {
|
|
451
480
|
rb_define_method(rb_cPhoneNumber, "e164", reinterpret_cast<VALUE (*)(...)>(rb_phone_number_e164), 0);
|
452
481
|
rb_define_method(rb_cPhoneNumber, "national", reinterpret_cast<VALUE (*)(...)>(rb_phone_number_national), 0);
|
453
482
|
|
454
|
-
// Raw National
|
455
|
-
raw_national_format.Add()->set_format("$1$2$3");
|
456
|
-
|
457
483
|
rb_define_method(rb_cPhoneNumber, "raw_national", reinterpret_cast<VALUE (*)(...)>(rb_phone_number_raw_national), 0);
|
484
|
+
rb_define_method(rb_cPhoneNumber, "dasherized_national",
|
485
|
+
reinterpret_cast<VALUE (*)(...)>(rb_phone_number_dasherized_national), 0);
|
458
486
|
rb_define_method(rb_cPhoneNumber, "international", reinterpret_cast<VALUE (*)(...)>(rb_phone_number_international),
|
459
487
|
0);
|
460
488
|
rb_define_method(rb_cPhoneNumber, "rfc3966", reinterpret_cast<VALUE (*)(...)>(rb_phone_number_rfc3966), 0);
|
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.0.
|
4
|
+
version: 1.0.5
|
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-
|
11
|
+
date: 2021-01-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.
|