gphone 0.1.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.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +21 -0
- data/LICENSE.txt +24 -0
- data/README.md +38 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/ext/gphone/Makefile +255 -0
- data/ext/gphone/extconf.rb +7 -0
- data/ext/gphone/gphone.cc +122 -0
- data/gphone.gemspec +68 -0
- data/spec/gphone_spec.rb +22 -0
- data/spec/spec_helper.rb +12 -0
- metadata +160 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem 'rice'
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
|
11
|
+
group :test do
|
12
|
+
gem 'rake-compiler'
|
13
|
+
end
|
14
|
+
|
15
|
+
group :development do
|
16
|
+
gem "rspec", "~> 2.8.0"
|
17
|
+
gem "rdoc", "~> 3.12"
|
18
|
+
gem "bundler", ">= 1.0.0"
|
19
|
+
gem "jeweler", "~> 1.8.4"
|
20
|
+
gem "simplecov", ">= 0"
|
21
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Copyright (c) 2012, Tobias Begalke
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
* Redistributions of source code must retain the above copyright
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
|
+
* Redistributions in binary form must reproduce the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
|
+
* Neither the name of the <organization> nor the
|
12
|
+
names of its contributors may be used to endorse or promote products
|
13
|
+
derived from this software without specific prior written permission.
|
14
|
+
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
16
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
17
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
19
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
20
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
21
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
22
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
23
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
24
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
gphone
|
2
|
+
======
|
3
|
+
|
4
|
+
Ruby bindings to Google's libphonenumber. With gphone you can parse,
|
5
|
+
validate and normalize and format phone numbers and determine their
|
6
|
+
type. So far this library offers only very basic coverage of the
|
7
|
+
features the C++ library offers.
|
8
|
+
|
9
|
+
Usage
|
10
|
+
-----
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
require 'gphone'
|
14
|
+
|
15
|
+
ph = GPhone.new('+49 09131/76352435', 'DE')
|
16
|
+
|
17
|
+
ph.valid?
|
18
|
+
> true
|
19
|
+
|
20
|
+
ph.possible?
|
21
|
+
> true
|
22
|
+
|
23
|
+
ph.normalize
|
24
|
+
> "+49913176352435"
|
25
|
+
|
26
|
+
ph.format_national
|
27
|
+
> "09131 76352435"
|
28
|
+
|
29
|
+
ph.type
|
30
|
+
> "fixed line"
|
31
|
+
```
|
32
|
+
|
33
|
+
|
34
|
+
Contribute
|
35
|
+
----------
|
36
|
+
|
37
|
+
Feel free to fork this repository and send me pull requests if you add
|
38
|
+
functionality.
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "gphone"
|
18
|
+
gem.homepage = "http://github.com/elcamino/gphone"
|
19
|
+
gem.license = "BSD"
|
20
|
+
gem.summary = %Q{ruby bindings for Google's libphonenumber}
|
21
|
+
gem.description = %Q{ruby bindings for Google's libphonenumber (see http://code.google.com/p/libphonenumber/)}
|
22
|
+
gem.email = "tob@spyz.org"
|
23
|
+
gem.authors = ["Tobias Begalke"]
|
24
|
+
gem.files += Dir['ext/gphone/*.{cc,rb}']
|
25
|
+
gem.require_paths = ['ext']
|
26
|
+
# dependencies defined in Gemfile
|
27
|
+
end
|
28
|
+
Jeweler::RubygemsDotOrgTasks.new
|
29
|
+
|
30
|
+
require 'rspec/core'
|
31
|
+
require 'rspec/core/rake_task'
|
32
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
33
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
34
|
+
end
|
35
|
+
|
36
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
37
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
38
|
+
spec.rcov = true
|
39
|
+
end
|
40
|
+
|
41
|
+
task :default => :spec
|
42
|
+
|
43
|
+
require 'rdoc/task'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
46
|
+
|
47
|
+
rdoc.rdoc_dir = 'rdoc'
|
48
|
+
rdoc.title = "gphone #{version}"
|
49
|
+
rdoc.rdoc_files.include('README*')
|
50
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
+
end
|
52
|
+
|
53
|
+
require 'rake/extensiontask'
|
54
|
+
Rake::ExtensionTask.new('gphone')
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/ext/gphone/Makefile
ADDED
@@ -0,0 +1,255 @@
|
|
1
|
+
|
2
|
+
SHELL = /bin/sh
|
3
|
+
|
4
|
+
# V=0 quiet, V=1 verbose. other values don't work.
|
5
|
+
V = 0
|
6
|
+
Q1 = $(V:1=)
|
7
|
+
Q = $(Q1:0=@)
|
8
|
+
n=$(NULLCMD)
|
9
|
+
ECHO1 = $(V:1=@$n)
|
10
|
+
ECHO = $(ECHO1:0=@echo)
|
11
|
+
|
12
|
+
#### Start of system configuration section. ####
|
13
|
+
|
14
|
+
srcdir = .
|
15
|
+
topdir = /usr/local/rvm/rubies/ruby-1.9.3-p327/include/ruby-1.9.1
|
16
|
+
hdrdir = /usr/local/rvm/rubies/ruby-1.9.3-p327/include/ruby-1.9.1
|
17
|
+
arch_hdrdir = /usr/local/rvm/rubies/ruby-1.9.3-p327/include/ruby-1.9.1/$(arch)
|
18
|
+
VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
|
19
|
+
|
20
|
+
prefix = $(DESTDIR)/usr/local/rvm/rubies/ruby-1.9.3-p327
|
21
|
+
|
22
|
+
rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
|
23
|
+
|
24
|
+
exec_prefix = $(prefix)
|
25
|
+
|
26
|
+
vendorhdrdir = $(rubyhdrdir)/vendor_ruby
|
27
|
+
|
28
|
+
sitehdrdir = $(rubyhdrdir)/site_ruby
|
29
|
+
|
30
|
+
rubyhdrdir = $(includedir)/$(RUBY_BASE_NAME)-$(ruby_version)
|
31
|
+
|
32
|
+
vendordir = $(rubylibprefix)/vendor_ruby
|
33
|
+
|
34
|
+
sitedir = $(rubylibprefix)/site_ruby
|
35
|
+
|
36
|
+
ridir = $(datarootdir)/$(RI_BASE_NAME)
|
37
|
+
|
38
|
+
mandir = $(datarootdir)/man
|
39
|
+
|
40
|
+
localedir = $(datarootdir)/locale
|
41
|
+
|
42
|
+
libdir = $(exec_prefix)/lib
|
43
|
+
|
44
|
+
psdir = $(docdir)
|
45
|
+
|
46
|
+
pdfdir = $(docdir)
|
47
|
+
|
48
|
+
dvidir = $(docdir)
|
49
|
+
|
50
|
+
htmldir = $(docdir)
|
51
|
+
|
52
|
+
infodir = $(datarootdir)/info
|
53
|
+
|
54
|
+
docdir = $(datarootdir)/doc/$(PACKAGE)
|
55
|
+
|
56
|
+
oldincludedir = $(DESTDIR)/usr/include
|
57
|
+
|
58
|
+
includedir = $(prefix)/include
|
59
|
+
|
60
|
+
localstatedir = $(prefix)/var
|
61
|
+
|
62
|
+
sharedstatedir = $(prefix)/com
|
63
|
+
|
64
|
+
sysconfdir = $(prefix)/etc
|
65
|
+
|
66
|
+
datadir = $(datarootdir)
|
67
|
+
|
68
|
+
datarootdir = $(prefix)/share
|
69
|
+
|
70
|
+
libexecdir = $(exec_prefix)/libexec
|
71
|
+
|
72
|
+
sbindir = $(exec_prefix)/sbin
|
73
|
+
|
74
|
+
bindir = $(exec_prefix)/bin
|
75
|
+
|
76
|
+
rubylibdir = $(rubylibprefix)/$(ruby_version)
|
77
|
+
|
78
|
+
archdir = $(rubylibdir)/$(arch)
|
79
|
+
|
80
|
+
sitelibdir = $(sitedir)/$(ruby_version)
|
81
|
+
|
82
|
+
sitearchdir = $(sitelibdir)/$(sitearch)
|
83
|
+
|
84
|
+
vendorlibdir = $(vendordir)/$(ruby_version)
|
85
|
+
|
86
|
+
vendorarchdir = $(vendorlibdir)/$(sitearch)
|
87
|
+
|
88
|
+
|
89
|
+
NULLCMD = :
|
90
|
+
|
91
|
+
CC = gcc
|
92
|
+
CXX = g++
|
93
|
+
LIBRUBY = $(LIBRUBY_SO)
|
94
|
+
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
95
|
+
LIBRUBYARG_SHARED = -Wl,-R -Wl,$(libdir) -L$(libdir) -l$(RUBY_SO_NAME)
|
96
|
+
LIBRUBYARG_STATIC = -Wl,-R -Wl,/usr/local/rvm/rubies/ruby-1.9.3-p327/lib -L/usr/local/rvm/rubies/ruby-1.9.3-p327/lib -lruby-static
|
97
|
+
empty =
|
98
|
+
OUTFLAG = -o $(empty)
|
99
|
+
COUTFLAG = -o $(empty)
|
100
|
+
|
101
|
+
RUBY_EXTCONF_H =
|
102
|
+
cflags = $(optflags) $(debugflags) $(warnflags)
|
103
|
+
optflags = -O3
|
104
|
+
debugflags = -ggdb
|
105
|
+
warnflags = -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration
|
106
|
+
CFLAGS = -fPIC -I/usr/local/rvm/usr/include -fPIC $(ARCH_FLAG)
|
107
|
+
INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
|
108
|
+
DEFS =
|
109
|
+
CPPFLAGS = $(DEFS) $(cppflags) -I/usr/local/rvm/gems/ruby-1.9.3-p327/gems/rice-1.4.3/ruby/lib/include
|
110
|
+
CXXFLAGS = $(CFLAGS) -Wall -g
|
111
|
+
ldflags = -L. -L/usr/local/rvm/usr/lib -rdynamic -Wl,-export-dynamic -L/usr/local/rvm/gems/ruby-1.9.3-p327/gems/rice-1.4.3/ruby/lib/lib
|
112
|
+
dldflags =
|
113
|
+
ARCH_FLAG =
|
114
|
+
DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
|
115
|
+
LDSHARED = g++ -shared
|
116
|
+
LDSHAREDXX = $(CXX) -shared
|
117
|
+
AR = ar
|
118
|
+
EXEEXT =
|
119
|
+
|
120
|
+
RUBY_BASE_NAME = ruby
|
121
|
+
RUBY_INSTALL_NAME = ruby
|
122
|
+
RUBY_SO_NAME = ruby
|
123
|
+
arch = x86_64-linux
|
124
|
+
sitearch = $(arch)
|
125
|
+
ruby_version = 1.9.1
|
126
|
+
ruby = /usr/local/rvm/rubies/ruby-1.9.3-p327/bin/ruby
|
127
|
+
RUBY = $(ruby)
|
128
|
+
RM = rm -f
|
129
|
+
RM_RF = $(RUBY) -run -e rm -- -rf
|
130
|
+
RMDIRS = rmdir --ignore-fail-on-non-empty -p
|
131
|
+
MAKEDIRS = /bin/mkdir -p
|
132
|
+
INSTALL = /usr/bin/install -c
|
133
|
+
INSTALL_PROG = $(INSTALL) -m 0755
|
134
|
+
INSTALL_DATA = $(INSTALL) -m 644
|
135
|
+
COPY = cp
|
136
|
+
TOUCH = exit >
|
137
|
+
|
138
|
+
#### End of system configuration section. ####
|
139
|
+
|
140
|
+
preload =
|
141
|
+
|
142
|
+
|
143
|
+
CXX = g++
|
144
|
+
|
145
|
+
libpath = . $(libdir)
|
146
|
+
LIBPATH = -L. -L$(libdir) -Wl,-R$(libdir)
|
147
|
+
DEFFILE =
|
148
|
+
|
149
|
+
CLEANFILES = mkmf.log
|
150
|
+
DISTCLEANFILES =
|
151
|
+
DISTCLEANDIRS =
|
152
|
+
|
153
|
+
extout =
|
154
|
+
extout_prefix =
|
155
|
+
target_prefix =
|
156
|
+
LOCAL_LIBS =
|
157
|
+
LIBS = -lphonenumber -lboost_thread -lrice -Wl,-R -Wl,/usr/local/rvm/rubies/ruby-1.9.3-p327/lib -L/usr/local/rvm/rubies/ruby-1.9.3-p327/lib -lruby -lpthread -lrt -ldl -lcrypt -lm -lc
|
158
|
+
SRCS = gphone.cc
|
159
|
+
OBJS = gphone.o
|
160
|
+
TARGET = gphone
|
161
|
+
DLLIB = $(TARGET).so
|
162
|
+
EXTSTATIC =
|
163
|
+
STATIC_LIB =
|
164
|
+
|
165
|
+
BINDIR = $(bindir)
|
166
|
+
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
167
|
+
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
168
|
+
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
169
|
+
HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
|
170
|
+
ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
|
171
|
+
|
172
|
+
TARGET_SO = $(DLLIB)
|
173
|
+
CLEANLIBS = $(TARGET).so
|
174
|
+
CLEANOBJS = *.o *.bak
|
175
|
+
|
176
|
+
all: $(DLLIB)
|
177
|
+
static: $(STATIC_LIB)
|
178
|
+
.PHONY: all install static install-so install-rb
|
179
|
+
.PHONY: clean clean-so clean-rb
|
180
|
+
|
181
|
+
clean-rb-default::
|
182
|
+
clean-rb::
|
183
|
+
clean-so::
|
184
|
+
clean: clean-so clean-rb-default clean-rb
|
185
|
+
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
|
186
|
+
|
187
|
+
distclean-rb-default::
|
188
|
+
distclean-rb::
|
189
|
+
distclean-so::
|
190
|
+
distclean: clean distclean-so distclean-rb-default distclean-rb
|
191
|
+
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
192
|
+
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
193
|
+
@-$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true
|
194
|
+
|
195
|
+
realclean: distclean
|
196
|
+
install: install-so install-rb
|
197
|
+
|
198
|
+
install-so: $(RUBYARCHDIR)/$(DLLIB)
|
199
|
+
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
|
200
|
+
-$(Q)$(MAKEDIRS) $(@D)
|
201
|
+
$(INSTALL_PROG) $(DLLIB) $(@D)
|
202
|
+
clean-static::
|
203
|
+
-$(Q)$(RM) $(STATIC_LIB)
|
204
|
+
install-rb: pre-install-rb install-rb-default
|
205
|
+
install-rb-default: pre-install-rb-default
|
206
|
+
pre-install-rb: Makefile
|
207
|
+
pre-install-rb-default: Makefile
|
208
|
+
pre-install-rb-default:
|
209
|
+
$(ECHO) installing default gphone libraries
|
210
|
+
./.RUBYARCHDIR.time:
|
211
|
+
$(Q) $(MAKEDIRS) $(RUBYARCHDIR)
|
212
|
+
$(Q) $(TOUCH) $@
|
213
|
+
|
214
|
+
site-install: site-install-so site-install-rb
|
215
|
+
site-install-so: install-so
|
216
|
+
site-install-rb: install-rb
|
217
|
+
|
218
|
+
.SUFFIXES: .c .m .cc .mm .cxx .cpp .C .o
|
219
|
+
|
220
|
+
.cc.o:
|
221
|
+
$(ECHO) compiling $(<)
|
222
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
223
|
+
|
224
|
+
.mm.o:
|
225
|
+
$(ECHO) compiling $(<)
|
226
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
227
|
+
|
228
|
+
.cxx.o:
|
229
|
+
$(ECHO) compiling $(<)
|
230
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
231
|
+
|
232
|
+
.cpp.o:
|
233
|
+
$(ECHO) compiling $(<)
|
234
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
235
|
+
|
236
|
+
.C.o:
|
237
|
+
$(ECHO) compiling $(<)
|
238
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
239
|
+
|
240
|
+
.c.o:
|
241
|
+
$(ECHO) compiling $(<)
|
242
|
+
$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
|
243
|
+
|
244
|
+
.m.o:
|
245
|
+
$(ECHO) compiling $(<)
|
246
|
+
$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
|
247
|
+
|
248
|
+
$(DLLIB): $(OBJS) Makefile
|
249
|
+
$(ECHO) linking shared-object $(DLLIB)
|
250
|
+
-$(Q)$(RM) $(@)
|
251
|
+
$(Q) $(LDSHAREDXX) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
$(OBJS): $(hdrdir)/ruby.h $(hdrdir)/ruby/defines.h $(arch_hdrdir)/ruby/config.h
|
@@ -0,0 +1,122 @@
|
|
1
|
+
#include "rice/Class.hpp"
|
2
|
+
#include "rice/String.hpp"
|
3
|
+
#include "rice/Data_Type.hpp"
|
4
|
+
#include "rice/Constructor.hpp"
|
5
|
+
#include <string>
|
6
|
+
#include <phonenumbers/phonenumberutil.h>
|
7
|
+
#include <phonenumbers/phonenumbermatcher.h>
|
8
|
+
|
9
|
+
using namespace std;
|
10
|
+
using namespace i18n::phonenumbers;
|
11
|
+
using namespace Rice;
|
12
|
+
|
13
|
+
namespace {
|
14
|
+
class GPhoneException
|
15
|
+
: public exception
|
16
|
+
{
|
17
|
+
virtual const char* what() const throw()
|
18
|
+
{
|
19
|
+
return "Not a valid phone number!";
|
20
|
+
}
|
21
|
+
};
|
22
|
+
|
23
|
+
class GPhone {
|
24
|
+
string raw_number;
|
25
|
+
string country_code;
|
26
|
+
PhoneNumber parsed_number;
|
27
|
+
PhoneNumberUtil::PhoneNumberType type;
|
28
|
+
|
29
|
+
public:
|
30
|
+
|
31
|
+
GPhone(const string number, const string cc) {
|
32
|
+
raw_number = number;
|
33
|
+
country_code = cc;
|
34
|
+
|
35
|
+
if (pu().Parse(raw_number, country_code, &parsed_number) != pu().NO_PARSING_ERROR) {
|
36
|
+
throw GPhoneException();
|
37
|
+
}
|
38
|
+
|
39
|
+
type = pu().GetNumberType(parsed_number);
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
string get_raw_number() { return raw_number; }
|
44
|
+
string get_country_code() { return country_code; }
|
45
|
+
|
46
|
+
PhoneNumberUtil& pu() {
|
47
|
+
return *PhoneNumberUtil::GetInstance();
|
48
|
+
}
|
49
|
+
|
50
|
+
const string normalize()
|
51
|
+
{
|
52
|
+
string formatted_number;
|
53
|
+
pu().Format(parsed_number, PhoneNumberUtil::E164, &formatted_number);
|
54
|
+
return formatted_number;
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
bool is_valid()
|
59
|
+
{
|
60
|
+
return pu().IsValidNumber(parsed_number);
|
61
|
+
}
|
62
|
+
|
63
|
+
bool is_possible()
|
64
|
+
{
|
65
|
+
return pu().IsPossibleNumber(parsed_number);
|
66
|
+
}
|
67
|
+
|
68
|
+
const string format_national()
|
69
|
+
{
|
70
|
+
string formatted_number;
|
71
|
+
pu().Format(parsed_number, PhoneNumberUtil::NATIONAL, &formatted_number);
|
72
|
+
return formatted_number;
|
73
|
+
}
|
74
|
+
|
75
|
+
const string get_type()
|
76
|
+
{
|
77
|
+
switch(type) {
|
78
|
+
case PhoneNumberUtil::FIXED_LINE:
|
79
|
+
return "fixed line";
|
80
|
+
case PhoneNumberUtil::MOBILE:
|
81
|
+
return "mobile";
|
82
|
+
case PhoneNumberUtil::TOLL_FREE:
|
83
|
+
return "toll free";
|
84
|
+
case PhoneNumberUtil::PREMIUM_RATE:
|
85
|
+
return "premium_rate";
|
86
|
+
case PhoneNumberUtil::SHARED_COST:
|
87
|
+
return "shared cost";
|
88
|
+
case PhoneNumberUtil::VOIP:
|
89
|
+
return "voip";
|
90
|
+
case PhoneNumberUtil::PERSONAL_NUMBER:
|
91
|
+
return "personal_number";
|
92
|
+
case PhoneNumberUtil::PAGER:
|
93
|
+
return "pager";
|
94
|
+
case PhoneNumberUtil::UAN:
|
95
|
+
return "uan";
|
96
|
+
case PhoneNumberUtil::VOICEMAIL:
|
97
|
+
return "voicemail";
|
98
|
+
default:
|
99
|
+
return NULL;
|
100
|
+
}
|
101
|
+
}
|
102
|
+
};
|
103
|
+
|
104
|
+
}
|
105
|
+
extern "C"
|
106
|
+
|
107
|
+
void Init_gphone() {
|
108
|
+
RUBY_TRY
|
109
|
+
{
|
110
|
+
Class rb_cGPhone = define_class<GPhone>("GPhone")
|
111
|
+
.define_constructor(Constructor<GPhone, const string, const string>())
|
112
|
+
.define_method("raw_number", &GPhone::get_raw_number)
|
113
|
+
.define_method("country_code", &GPhone::get_country_code)
|
114
|
+
.define_method("valid?", &GPhone::is_valid)
|
115
|
+
.define_method("possible?", &GPhone::is_possible)
|
116
|
+
.define_method("format_national", &GPhone::format_national)
|
117
|
+
.define_method("normalize", &GPhone::normalize)
|
118
|
+
.define_method("type", &GPhone::get_type);
|
119
|
+
}
|
120
|
+
RUBY_CATCH
|
121
|
+
}
|
122
|
+
|
data/gphone.gemspec
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "gphone"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Tobias Begalke"]
|
12
|
+
s.date = "2012-11-14"
|
13
|
+
s.description = "ruby bindings for Google's libphonenumber (see http://code.google.com/p/libphonenumber/)"
|
14
|
+
s.email = "tob@spyz.org"
|
15
|
+
s.extensions = ["ext/gphone/extconf.rb"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.md"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".rspec",
|
23
|
+
"Gemfile",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.md",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"ext/gphone/Makefile",
|
29
|
+
"ext/gphone/extconf.rb",
|
30
|
+
"ext/gphone/gphone.cc",
|
31
|
+
"gphone.gemspec",
|
32
|
+
"spec/gphone_spec.rb",
|
33
|
+
"spec/spec_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = "http://github.com/elcamino/gphone"
|
36
|
+
s.licenses = ["BSD"]
|
37
|
+
s.require_paths = ["ext"]
|
38
|
+
s.rubygems_version = "1.8.24"
|
39
|
+
s.summary = "ruby bindings for Google's libphonenumber"
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_runtime_dependency(%q<rice>, [">= 0"])
|
46
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
47
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
48
|
+
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
49
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
50
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<rice>, [">= 0"])
|
53
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
54
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
55
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
56
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
57
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
58
|
+
end
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<rice>, [">= 0"])
|
61
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
62
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
63
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
64
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
65
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
data/spec/gphone_spec.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "GPhone.new('+49 09131/76352435', 'DE') (ie. with a valid number)" do
|
4
|
+
subject { GPhone.new('+49 09131/76352435', 'DE') }
|
5
|
+
|
6
|
+
it { should be }
|
7
|
+
|
8
|
+
it { should be_an_instance_of GPhone }
|
9
|
+
its(:valid?) { should be }
|
10
|
+
its(:possible?) { should be }
|
11
|
+
its(:raw_number) { should == '+49 09131/76352435' }
|
12
|
+
its(:country_code) { should == 'DE' }
|
13
|
+
its(:normalize) { should == '+49913176352435' }
|
14
|
+
its(:format_national) { should == '09131 76352435' }
|
15
|
+
its(:type) { should == 'fixed line' }
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
describe "GPhone.new('09543657 4567474567 4674', 'DE') (ie. with an invalid number)" do
|
21
|
+
it { lambda { GPhone.new('09543657 4567474567 4674', 'DE') }.should raise_error }
|
22
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'gphone'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gphone
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tobias Begalke
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rice
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.8.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.8.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rdoc
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.12'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.12'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.0.0
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.0.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: jeweler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.8.4
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.8.4
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: simplecov
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: ruby bindings for Google's libphonenumber (see http://code.google.com/p/libphonenumber/)
|
111
|
+
email: tob@spyz.org
|
112
|
+
executables: []
|
113
|
+
extensions:
|
114
|
+
- ext/gphone/extconf.rb
|
115
|
+
extra_rdoc_files:
|
116
|
+
- LICENSE.txt
|
117
|
+
- README.md
|
118
|
+
files:
|
119
|
+
- .document
|
120
|
+
- .rspec
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- VERSION
|
126
|
+
- ext/gphone/Makefile
|
127
|
+
- ext/gphone/extconf.rb
|
128
|
+
- ext/gphone/gphone.cc
|
129
|
+
- gphone.gemspec
|
130
|
+
- spec/gphone_spec.rb
|
131
|
+
- spec/spec_helper.rb
|
132
|
+
homepage: http://github.com/elcamino/gphone
|
133
|
+
licenses:
|
134
|
+
- BSD
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- ext
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
141
|
+
requirements:
|
142
|
+
- - ! '>='
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
segments:
|
146
|
+
- 0
|
147
|
+
hash: -1938156335739255995
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ! '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 1.8.24
|
157
|
+
signing_key:
|
158
|
+
specification_version: 3
|
159
|
+
summary: ruby bindings for Google's libphonenumber
|
160
|
+
test_files: []
|