mini_phone 1.1.4 → 1.1.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/ext/mini_phone/mini_phone.cc +61 -48
- data/lib/mini_phone/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3a42ec155de4fb7b2a8ea675ac0380274f23b38795c0eb0e73c0efb3ed4d8a5
|
4
|
+
data.tar.gz: aaec470245e26e61d277a329340833eef93fa22939395273eabba719f977408e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99128e918a87c4e875191b47177507da77be675aafb7a7bec430457ab420c4b5081872407b31d07de04fc24233e57d14e711a019f49939d3db89e757eeeab1a1
|
7
|
+
data.tar.gz: a9676a2d17fd3a5e0d178159ed9b413ea73469790e5219040cfa80e5679fce578ac0e80e95b60366cdd23f4961744eba65740464e6bd05bb1549805547862b1f
|
@@ -16,7 +16,7 @@ static RepeatedPtrField<NumberFormat> dasherized_national_format;
|
|
16
16
|
|
17
17
|
extern "C" struct PhoneNumberInfo { PhoneNumber *phone_number; };
|
18
18
|
|
19
|
-
extern "C" size_t phone_number_info_size(const void *data) { return sizeof(PhoneNumberInfo)
|
19
|
+
extern "C" size_t phone_number_info_size(const void *data) { return sizeof(PhoneNumberInfo); }
|
20
20
|
|
21
21
|
extern "C" void phone_number_info_free(void *data) {
|
22
22
|
PhoneNumberInfo *phone_number_info = static_cast<PhoneNumberInfo *>(data);
|
@@ -66,9 +66,9 @@ static inline VALUE is_phone_number_valid(VALUE self, VALUE str, VALUE cc) {
|
|
66
66
|
}
|
67
67
|
|
68
68
|
extern "C" VALUE rb_is_phone_number_valid(VALUE self, VALUE str) {
|
69
|
-
VALUE
|
69
|
+
VALUE input_region_code = rb_iv_get(rb_mMiniPhone, "@default_country");
|
70
70
|
|
71
|
-
return is_phone_number_valid(self, str,
|
71
|
+
return is_phone_number_valid(self, str, input_region_code);
|
72
72
|
}
|
73
73
|
|
74
74
|
extern "C" VALUE rb_normalize_digits_only(VALUE self, VALUE str) {
|
@@ -105,9 +105,9 @@ extern "C" VALUE rb_is_phone_number_possible(VALUE self, VALUE str) {
|
|
105
105
|
PhoneNumber parsed_number;
|
106
106
|
const PhoneNumberUtil &phone_util(*PhoneNumberUtil::GetInstance());
|
107
107
|
|
108
|
-
VALUE
|
108
|
+
VALUE input_region_code = rb_iv_get(rb_mMiniPhone, "@default_country");
|
109
109
|
std::string phone_number(RSTRING_PTR(str), RSTRING_LEN(str));
|
110
|
-
std::string country_code(RSTRING_PTR(
|
110
|
+
std::string country_code(RSTRING_PTR(input_region_code), RSTRING_LEN(input_region_code));
|
111
111
|
|
112
112
|
auto result = phone_util.Parse(phone_number, country_code, &parsed_number);
|
113
113
|
|
@@ -282,28 +282,6 @@ extern "C" VALUE rb_phone_number_raw_international(VALUE self) {
|
|
282
282
|
return rb_iv_set(self, "@raw_international", result);
|
283
283
|
}
|
284
284
|
|
285
|
-
extern "C" VALUE rb_phone_number_valid_eh(VALUE self) {
|
286
|
-
if (rb_ivar_defined(self, rb_intern("@valid"))) {
|
287
|
-
return rb_iv_get(self, "@valid");
|
288
|
-
}
|
289
|
-
|
290
|
-
std::string formatted_number;
|
291
|
-
PhoneNumberInfo *phone_number_info;
|
292
|
-
TypedData_Get_Struct(self, PhoneNumberInfo, &phone_number_info_type, phone_number_info);
|
293
|
-
|
294
|
-
const PhoneNumberUtil &phone_util(*PhoneNumberUtil::GetInstance());
|
295
|
-
|
296
|
-
if (phone_util.IsValidNumber(*phone_number_info->phone_number)) {
|
297
|
-
return rb_iv_set(self, "@valid", Qtrue);
|
298
|
-
} else {
|
299
|
-
return rb_iv_set(self, "@valid", Qfalse);
|
300
|
-
}
|
301
|
-
}
|
302
|
-
|
303
|
-
extern "C" VALUE rb_phone_number_invalid_eh(VALUE self) {
|
304
|
-
return rb_phone_number_valid_eh(self) == Qtrue ? Qfalse : Qtrue;
|
305
|
-
}
|
306
|
-
|
307
285
|
extern "C" VALUE rb_phone_number_possible_eh(VALUE self) {
|
308
286
|
if (rb_ivar_defined(self, rb_intern("@possible"))) {
|
309
287
|
return rb_iv_get(self, "@possible");
|
@@ -348,14 +326,6 @@ extern "C" VALUE rb_phone_number_match_eh(VALUE self, VALUE other) {
|
|
348
326
|
return Qfalse;
|
349
327
|
}
|
350
328
|
|
351
|
-
VALUE self_input = rb_iv_get(self, "@input");
|
352
|
-
VALUE other_input = rb_iv_get(other, "@input");
|
353
|
-
|
354
|
-
// If inputs are the exact same, the result is as well
|
355
|
-
if (rb_eql(self_input, other_input)) {
|
356
|
-
return Qtrue;
|
357
|
-
}
|
358
|
-
|
359
329
|
const PhoneNumberUtil &phone_util(*PhoneNumberUtil::GetInstance());
|
360
330
|
|
361
331
|
PhoneNumberInfo *self_info;
|
@@ -364,6 +334,10 @@ extern "C" VALUE rb_phone_number_match_eh(VALUE self, VALUE other) {
|
|
364
334
|
PhoneNumberInfo *other_info;
|
365
335
|
TypedData_Get_Struct(other, PhoneNumberInfo, &phone_number_info_type, other_info);
|
366
336
|
|
337
|
+
if (self_info->phone_number->raw_input() == other_info->phone_number->raw_input()) {
|
338
|
+
return Qtrue;
|
339
|
+
}
|
340
|
+
|
367
341
|
if (phone_util.IsNumberMatch(*other_info->phone_number, *self_info->phone_number) == PhoneNumberUtil::EXACT_MATCH) {
|
368
342
|
return Qtrue;
|
369
343
|
} else {
|
@@ -455,7 +429,18 @@ extern "C" VALUE rb_phone_number_area_code(VALUE self) {
|
|
455
429
|
return rb_iv_set(self, "@area_code", result);
|
456
430
|
}
|
457
431
|
|
458
|
-
extern "C" VALUE rb_phone_number_to_s(VALUE self) {
|
432
|
+
extern "C" VALUE rb_phone_number_to_s(VALUE self) {
|
433
|
+
PhoneNumberInfo *phone_number_info;
|
434
|
+
TypedData_Get_Struct(self, PhoneNumberInfo, &phone_number_info_type, phone_number_info);
|
435
|
+
PhoneNumber *phone_number = phone_number_info->phone_number;
|
436
|
+
std::string raw_input = phone_number->raw_input();
|
437
|
+
|
438
|
+
if (raw_input == "") {
|
439
|
+
return Qnil;
|
440
|
+
} else {
|
441
|
+
return rb_str_new(raw_input.c_str(), raw_input.size());
|
442
|
+
}
|
443
|
+
}
|
459
444
|
|
460
445
|
static inline void setup_formats() {
|
461
446
|
// Raw
|
@@ -469,18 +454,49 @@ static inline void setup_formats() {
|
|
469
454
|
dsh_fmt->set_format("$1-$2-$3");
|
470
455
|
}
|
471
456
|
|
457
|
+
extern "C" VALUE rb_phone_number_valid_eh(VALUE self) {
|
458
|
+
if (rb_ivar_defined(self, rb_intern("@valid"))) {
|
459
|
+
return rb_iv_get(self, "@valid");
|
460
|
+
}
|
461
|
+
|
462
|
+
std::string formatted_number;
|
463
|
+
PhoneNumberInfo *phone_number_info;
|
464
|
+
VALUE input_region_code = rb_iv_get(self, "@input_region_code");
|
465
|
+
TypedData_Get_Struct(self, PhoneNumberInfo, &phone_number_info_type, phone_number_info);
|
466
|
+
|
467
|
+
if (NIL_P(input_region_code)) {
|
468
|
+
input_region_code = rb_iv_get(rb_mMiniPhone, "@default_country");
|
469
|
+
}
|
470
|
+
|
471
|
+
const PhoneNumberUtil &phone_util(*PhoneNumberUtil::GetInstance());
|
472
|
+
|
473
|
+
if (!rb_str_equal(input_region_code, rb_str_new_literal("ZZ")) &&
|
474
|
+
!rb_str_equal(rb_phone_number_region_code(self), input_region_code)) {
|
475
|
+
return rb_iv_set(self, "@valid", Qfalse);
|
476
|
+
}
|
477
|
+
|
478
|
+
if (phone_util.IsValidNumber(*phone_number_info->phone_number)) {
|
479
|
+
return rb_iv_set(self, "@valid", Qtrue);
|
480
|
+
} else {
|
481
|
+
return rb_iv_set(self, "@valid", Qfalse);
|
482
|
+
}
|
483
|
+
}
|
484
|
+
|
485
|
+
extern "C" VALUE rb_phone_number_invalid_eh(VALUE self) {
|
486
|
+
return rb_phone_number_valid_eh(self) == Qtrue ? Qfalse : Qtrue;
|
487
|
+
}
|
488
|
+
|
472
489
|
extern "C" VALUE rb_phone_number_initialize(int argc, VALUE *argv, VALUE self) {
|
473
490
|
VALUE str;
|
474
|
-
VALUE
|
491
|
+
VALUE input_region_code;
|
475
492
|
|
476
|
-
rb_scan_args(argc, argv, "11", &str, &
|
493
|
+
rb_scan_args(argc, argv, "11", &str, &input_region_code);
|
494
|
+
rb_iv_set(self, "@input_region_code", input_region_code);
|
477
495
|
|
478
|
-
if (NIL_P(
|
479
|
-
|
496
|
+
if (NIL_P(input_region_code)) {
|
497
|
+
input_region_code = rb_iv_get(rb_mMiniPhone, "@default_country");
|
480
498
|
}
|
481
499
|
|
482
|
-
rb_iv_set(self, "@input", str);
|
483
|
-
|
484
500
|
if (FIXNUM_P(str)) {
|
485
501
|
str = rb_fix2str(str, 10);
|
486
502
|
} else if (!RB_TYPE_P(str, T_STRING)) {
|
@@ -495,9 +511,9 @@ extern "C" VALUE rb_phone_number_initialize(int argc, VALUE *argv, VALUE self) {
|
|
495
511
|
const PhoneNumberUtil &phone_util(*PhoneNumberUtil::GetInstance());
|
496
512
|
|
497
513
|
std::string phone_number(RSTRING_PTR(str), RSTRING_LEN(str));
|
498
|
-
std::string country_code(RSTRING_PTR(
|
514
|
+
std::string country_code(RSTRING_PTR(input_region_code), RSTRING_LEN(input_region_code));
|
499
515
|
|
500
|
-
auto result = phone_util.
|
516
|
+
auto result = phone_util.ParseAndKeepRawInput(phone_number, country_code, &parsed_number);
|
501
517
|
|
502
518
|
if (result != PhoneNumberUtil::NO_PARSING_ERROR) {
|
503
519
|
rb_phone_number_nullify_ivars(self);
|
@@ -505,10 +521,6 @@ extern "C" VALUE rb_phone_number_initialize(int argc, VALUE *argv, VALUE self) {
|
|
505
521
|
phone_number_info->phone_number->Swap(&parsed_number);
|
506
522
|
}
|
507
523
|
|
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
524
|
return self;
|
513
525
|
}
|
514
526
|
|
@@ -565,5 +577,6 @@ extern "C" void Init_mini_phone(void) {
|
|
565
577
|
rb_define_method(rb_cPhoneNumber, "type", reinterpret_cast<VALUE (*)(...)>(rb_phone_number_type), 0);
|
566
578
|
rb_define_method(rb_cPhoneNumber, "area_code", reinterpret_cast<VALUE (*)(...)>(rb_phone_number_area_code), 0);
|
567
579
|
rb_define_method(rb_cPhoneNumber, "to_s", reinterpret_cast<VALUE (*)(...)>(rb_phone_number_to_s), 0);
|
580
|
+
rb_define_method(rb_cPhoneNumber, "raw_input", reinterpret_cast<VALUE (*)(...)>(rb_phone_number_to_s), 0);
|
568
581
|
rb_define_method(rb_cPhoneNumber, "==", reinterpret_cast<VALUE (*)(...)>(rb_phone_number_match_eh), 1);
|
569
582
|
}
|
data/lib/mini_phone/version.rb
CHANGED