mini_phone 1.0.2 → 1.0.3
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/Rakefile +6 -2
- data/ext/mini_phone/mini_phone.cc +34 -4
- 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: 8f19ec27523bfdcd42b72b4421441b4016b4bf86c94f91f527e10bf5a33d1a16
|
4
|
+
data.tar.gz: 7ab2cf83930eaa1c35f7bf2a2faa7afded85238b8a69bf8822013f3f33ee274a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 853cc1202032f2c6f2fec744de57bfdabac907116fd1495060b65c5d51da060dbf317f253ca3179787f2de9162c7961e83d3f1c39909bbf7ae252262dcfaf7e4
|
7
|
+
data.tar.gz: 3965cf5f9798b3529eab55f0eb24b3532950f306005fca4655589d8d27c925028115a976fa623af6ca16e715aa6f8f9993cd8716779356f5c194b7cc5f7d4e6f
|
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 :
|
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:'"
|
@@ -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;
|
@@ -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);
|
@@ -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");
|
@@ -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
|
-
|
355
|
-
rb_define_module_function(rb_mMiniPhone, "default_country",
|
356
|
-
|
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);
|
data/lib/mini_phone/version.rb
CHANGED