gphone 0.2.2 → 0.3.0
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/VERSION +1 -1
- data/ext/gphone/gphone.cc +50 -0
- data/ext/gphone/gphone_ruby.cc +3 -0
- data/gphone.gemspec +3 -3
- data/spec/gphone_spec.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9345357baa42222d0a0fb7a47dab16542f28013
|
4
|
+
data.tar.gz: c28779d3c930ad8788bd2daced1759809192b8f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 802a4aa361f20e82dbd56b0406fac04e4a6f918161e3ff51213dcb68e454547eec5e228adb397c6b2b2b4778c62aea4d77c18706731cbc9e5fe9fd3d759d435a
|
7
|
+
data.tar.gz: da9d3e32e272f00c04a9867d029cb7ba69e285ff791bc589e23fb732d5d9a6ac1615f61c0b1c3e0c2db06f022de7a1ef604053d188515c6087008f1294a7f73e
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/ext/gphone/gphone.cc
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
#include "rice/Data_Type.hpp"
|
4
4
|
#include "rice/Constructor.hpp"
|
5
5
|
#include <string>
|
6
|
+
#include <iostream>
|
6
7
|
#include <phonenumbers/phonenumberutil.h>
|
7
8
|
#include <phonenumbers/phonenumbermatcher.h>
|
8
9
|
|
@@ -108,6 +109,55 @@ namespace {
|
|
108
109
|
return formatted_number;
|
109
110
|
}
|
110
111
|
|
112
|
+
const string national_prefix()
|
113
|
+
{
|
114
|
+
string region_code;
|
115
|
+
string national_prefix;
|
116
|
+
|
117
|
+
pu().GetRegionCodeForCountryCode(parsed_number.country_code(), ®ion_code);
|
118
|
+
pu().GetNddPrefixForRegion(region_code, true, &national_prefix);
|
119
|
+
|
120
|
+
return national_prefix;
|
121
|
+
}
|
122
|
+
|
123
|
+
const string area_code()
|
124
|
+
{
|
125
|
+
string area_code;
|
126
|
+
string national_significant_number;
|
127
|
+
string region_code;
|
128
|
+
|
129
|
+
pu().GetNationalSignificantNumber(parsed_number, &national_significant_number);
|
130
|
+
pu().GetRegionCodeForCountryCode(parsed_number.country_code(), ®ion_code);
|
131
|
+
|
132
|
+
|
133
|
+
int area_code_length = pu().GetLengthOfGeographicalAreaCode(parsed_number);
|
134
|
+
|
135
|
+
if (area_code_length > 0) {
|
136
|
+
area_code = national_significant_number.substr(0, area_code_length);
|
137
|
+
} else {
|
138
|
+
area_code = "";
|
139
|
+
}
|
140
|
+
|
141
|
+
return area_code;
|
142
|
+
}
|
143
|
+
|
144
|
+
const string subscriber_number()
|
145
|
+
{
|
146
|
+
string subscriber_number;
|
147
|
+
string national_significant_number;
|
148
|
+
pu().GetNationalSignificantNumber(parsed_number, &national_significant_number);
|
149
|
+
|
150
|
+
int area_code_length = pu().GetLengthOfGeographicalAreaCode(parsed_number);
|
151
|
+
|
152
|
+
if (area_code_length > 0) {
|
153
|
+
subscriber_number = national_significant_number.substr(area_code_length, string::npos);
|
154
|
+
} else {
|
155
|
+
subscriber_number = national_significant_number;
|
156
|
+
}
|
157
|
+
|
158
|
+
return subscriber_number;
|
159
|
+
}
|
160
|
+
|
111
161
|
const string get_type()
|
112
162
|
{
|
113
163
|
switch(type) {
|
data/ext/gphone/gphone_ruby.cc
CHANGED
@@ -18,6 +18,9 @@ void Init_gphone() {
|
|
18
18
|
.define_method("possible?", &GPhone::is_possible)
|
19
19
|
.define_method("format_national", &GPhone::format_national)
|
20
20
|
.define_method("normalize", &GPhone::normalize)
|
21
|
+
.define_method("national_prefix", &GPhone::national_prefix)
|
22
|
+
.define_method("area_code", &GPhone::area_code)
|
23
|
+
.define_method("subscriber_number", &GPhone::subscriber_number)
|
21
24
|
.define_method("type", &GPhone::get_type);
|
22
25
|
|
23
26
|
Class rb_cGPhoneOfflineGeocoder = define_class<GPhoneOfflineGeocoder>("GPhoneOfflineGeocoder")
|
data/gphone.gemspec
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: gphone 0.
|
5
|
+
# stub: gphone 0.3.0 ruby ext
|
6
6
|
# stub: ext/gphone/extconf.rb
|
7
7
|
|
8
8
|
Gem::Specification.new do |s|
|
9
9
|
s.name = "gphone"
|
10
|
-
s.version = "0.
|
10
|
+
s.version = "0.3.0"
|
11
11
|
|
12
12
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
13
13
|
s.require_paths = ["ext"]
|
14
14
|
s.authors = ["Tobias Begalke"]
|
15
|
-
s.date = "
|
15
|
+
s.date = "2016-01-08"
|
16
16
|
s.description = "ruby bindings for Google's libphonenumber (see http://code.google.com/p/libphonenumber/)"
|
17
17
|
s.email = "tob@spyz.org"
|
18
18
|
s.extensions = ["ext/gphone/extconf.rb"]
|
data/spec/gphone_spec.rb
CHANGED
@@ -21,6 +21,9 @@ describe "GPhone.new('+49 09131/76352435', 'DE') (ie. with a valid number)" do
|
|
21
21
|
its(:national_number) { should == 913176352435 }
|
22
22
|
its(:normalize) { should == '+49913176352435' }
|
23
23
|
its(:format_national) { should == '09131 76352435' }
|
24
|
+
its(:area_code) { should == '9131' }
|
25
|
+
its(:subscriber_number) { should == '76352435' }
|
26
|
+
its(:national_prefix) { should == '0' }
|
24
27
|
its(:type) { should == 'fixed line' }
|
25
28
|
|
26
29
|
end
|
@@ -46,6 +49,9 @@ describe "GPhone.new('09131/76352435', 'DE') (with a valid number but sans count
|
|
46
49
|
its(:national_number) { should == 913176352435 }
|
47
50
|
its(:normalize) { should == '+49913176352435' }
|
48
51
|
its(:format_national) { should == '09131 76352435' }
|
52
|
+
its(:area_code) { should == '9131' }
|
53
|
+
its(:subscriber_number) { should == '76352435' }
|
54
|
+
its(:national_prefix) { should == '0' }
|
49
55
|
its(:type) { should == 'fixed line' }
|
50
56
|
end
|
51
57
|
|
@@ -71,6 +77,9 @@ describe "GPhone.new('+499131/76352435') (with a valid number but sans country p
|
|
71
77
|
its(:national_number) { should == 913176352435 }
|
72
78
|
its(:normalize) { should == '+49913176352435' }
|
73
79
|
its(:format_national) { should == '09131 76352435' }
|
80
|
+
its(:area_code) { should == '9131' }
|
81
|
+
its(:subscriber_number) { should == '76352435' }
|
82
|
+
its(:national_prefix) { should == '0' }
|
74
83
|
its(:type) { should == 'fixed line' }
|
75
84
|
end
|
76
85
|
|
@@ -101,6 +110,9 @@ describe "GPhone.new('+12069735100') (i.e. a fully qualified number)" do
|
|
101
110
|
its(:national_number) { should == 2069735100 }
|
102
111
|
its(:normalize) { should == '+12069735100' }
|
103
112
|
its(:format_national) { should == '(206) 973-5100' }
|
113
|
+
its(:area_code) { should == '206' }
|
114
|
+
its(:subscriber_number) { should == '9735100' }
|
115
|
+
its(:national_prefix) { should == '1' }
|
104
116
|
its(:type) { should == "unknown" }
|
105
117
|
end
|
106
118
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gphone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Begalke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rice
|