phonelib 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.rdoc +5 -1
- data/data/PhoneNumberMetaData.xml +910 -3073
- data/data/phone_data.yml +670 -1683
- data/lib/phonelib.rb +3 -4
- data/lib/phonelib/core.rb +40 -20
- data/lib/phonelib/phone.rb +12 -8
- data/lib/phonelib/version.rb +1 -1
- data/lib/tasks/phonelib_tasks.rake +2 -2
- data/lib/validators/phone_validator.rb +40 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +28 -15
- data/test/dummy/log/test.log +3738 -454
- data/test/dummy/test/functional/phones_controller_test.rb +1 -0
- data/test/phonelib_test.rb +26 -0
- metadata +121 -114
- data/lib/phonelib/validators.rb +0 -47
data/test/phonelib_test.rb
CHANGED
@@ -17,6 +17,13 @@ class PhonelibTest < Test::Unit::TestCase
|
|
17
17
|
assert !@phone.valid?
|
18
18
|
assert @phone.possible?
|
19
19
|
end
|
20
|
+
|
21
|
+
context 'with international formatting' do
|
22
|
+
setup { @phone = Phonelib.parse('+1 (972) 123-4567', 'US') }
|
23
|
+
should 'return exact original' do
|
24
|
+
assert_equal '+1 (972) 123-4567', @phone.original
|
25
|
+
end
|
26
|
+
end
|
20
27
|
end
|
21
28
|
|
22
29
|
context '.valid?' do
|
@@ -172,4 +179,23 @@ class PhonelibTest < Test::Unit::TestCase
|
|
172
179
|
assert_equal '1234567', phone.national
|
173
180
|
end
|
174
181
|
end
|
182
|
+
|
183
|
+
context 'default_country' do
|
184
|
+
should 'be invalid with no default country set' do
|
185
|
+
phone = Phonelib.parse('541234567')
|
186
|
+
assert !phone.valid?
|
187
|
+
end
|
188
|
+
|
189
|
+
should 'valid with default country set' do
|
190
|
+
Phonelib.default_country = :IL
|
191
|
+
phone = Phonelib.parse('541234567')
|
192
|
+
assert phone.valid?
|
193
|
+
end
|
194
|
+
|
195
|
+
should 'valid with wrong default country set' do
|
196
|
+
Phonelib.default_country = :UA
|
197
|
+
phone = Phonelib.parse('972541234567')
|
198
|
+
assert phone.valid?
|
199
|
+
end
|
200
|
+
end
|
175
201
|
end
|
metadata
CHANGED
@@ -1,71 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phonelib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Vadim Senderovich
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-09-12 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rails
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 3.1.0
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.1.0
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: sqlite3
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - '>='
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: nokogiri
|
38
|
-
requirement:
|
39
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
|
-
- -
|
45
|
+
- - '>='
|
42
46
|
- !ruby/object:Gem::Version
|
43
47
|
version: '0'
|
44
48
|
type: :development
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
47
55
|
- !ruby/object:Gem::Dependency
|
48
56
|
name: pry
|
49
|
-
requirement:
|
50
|
-
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
51
58
|
requirements:
|
52
|
-
- -
|
59
|
+
- - '>='
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: '0'
|
55
62
|
type: :development
|
56
63
|
prerelease: false
|
57
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: shoulda-context
|
60
|
-
requirement:
|
61
|
-
none: false
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
62
72
|
requirements:
|
63
|
-
- -
|
73
|
+
- - '>='
|
64
74
|
- !ruby/object:Gem::Version
|
65
75
|
version: '0'
|
66
76
|
type: :development
|
67
77
|
prerelease: false
|
68
|
-
version_requirements:
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: Google libphonenumber library was taken as a basis for this gem. Gem
|
70
84
|
uses its data file for validations and number formatting.
|
71
85
|
email:
|
@@ -76,147 +90,140 @@ extra_rdoc_files: []
|
|
76
90
|
files:
|
77
91
|
- data/phone_data.yml
|
78
92
|
- data/PhoneNumberMetaData.xml
|
93
|
+
- lib/phonelib.rb
|
94
|
+
- lib/phonelib/version.rb
|
79
95
|
- lib/phonelib/phone.rb
|
80
|
-
- lib/phonelib/validators.rb
|
81
96
|
- lib/phonelib/core.rb
|
82
|
-
- lib/
|
83
|
-
- lib/phonelib.rb
|
97
|
+
- lib/validators/phone_validator.rb
|
84
98
|
- lib/tasks/phonelib_tasks.rake
|
85
99
|
- MIT-LICENSE
|
86
100
|
- Rakefile
|
87
101
|
- README.rdoc
|
88
|
-
- test/
|
89
|
-
- test/dummy/
|
90
|
-
- test/dummy/
|
91
|
-
- test/dummy/db/migrate/20130122075331_add_possible_number_to_phone.rb
|
92
|
-
- test/dummy/db/development.sqlite3
|
93
|
-
- test/dummy/config.ru
|
94
|
-
- test/dummy/config/initializers/backtrace_silencers.rb
|
102
|
+
- test/phonelib_test.rb
|
103
|
+
- test/dummy/config/database.yml
|
104
|
+
- test/dummy/config/initializers/session_store.rb
|
95
105
|
- test/dummy/config/initializers/wrap_parameters.rb
|
106
|
+
- test/dummy/config/initializers/secret_token.rb
|
96
107
|
- test/dummy/config/initializers/mime_types.rb
|
108
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
97
109
|
- test/dummy/config/initializers/inflections.rb
|
98
|
-
- test/dummy/config/initializers/session_store.rb
|
99
|
-
- test/dummy/config/initializers/secret_token.rb
|
100
110
|
- test/dummy/config/environments/development.rb
|
101
|
-
- test/dummy/config/environments/production.rb
|
102
111
|
- test/dummy/config/environments/test.rb
|
103
|
-
- test/dummy/config/
|
104
|
-
- test/dummy/config/boot.rb
|
112
|
+
- test/dummy/config/environments/production.rb
|
105
113
|
- test/dummy/config/environment.rb
|
106
|
-
- test/dummy/config/routes.rb
|
107
114
|
- test/dummy/config/locales/en.yml
|
108
|
-
- test/dummy/config/
|
109
|
-
- test/dummy/
|
110
|
-
- test/dummy/
|
111
|
-
- test/dummy/public/favicon.ico
|
112
|
-
- test/dummy/public/500.html
|
113
|
-
- test/dummy/test/fixtures/phones.yml
|
114
|
-
- test/dummy/test/unit/helpers/phones_helper_test.rb
|
115
|
-
- test/dummy/test/unit/phone_test.rb
|
116
|
-
- test/dummy/test/functional/phones_controller_test.rb
|
117
|
-
- test/dummy/README.rdoc
|
118
|
-
- test/dummy/log/development.log
|
119
|
-
- test/dummy/log/test.log
|
120
|
-
- test/dummy/Rakefile
|
121
|
-
- test/dummy/script/rails
|
122
|
-
- test/dummy/app/views/layouts/application.html.erb
|
123
|
-
- test/dummy/app/views/phones/_form.html.erb
|
124
|
-
- test/dummy/app/views/phones/index.html.erb
|
125
|
-
- test/dummy/app/views/phones/show.html.erb
|
126
|
-
- test/dummy/app/views/phones/edit.html.erb
|
127
|
-
- test/dummy/app/views/phones/new.html.erb
|
115
|
+
- test/dummy/config/boot.rb
|
116
|
+
- test/dummy/config/application.rb
|
117
|
+
- test/dummy/config/routes.rb
|
128
118
|
- test/dummy/app/models/phone.rb
|
129
|
-
- test/dummy/app/helpers/application_helper.rb
|
130
|
-
- test/dummy/app/helpers/phones_helper.rb
|
131
|
-
- test/dummy/app/controllers/phones_controller.rb
|
132
119
|
- test/dummy/app/controllers/application_controller.rb
|
120
|
+
- test/dummy/app/controllers/phones_controller.rb
|
121
|
+
- test/dummy/app/assets/stylesheets/application.css
|
133
122
|
- test/dummy/app/assets/stylesheets/scaffold.css
|
134
123
|
- test/dummy/app/assets/stylesheets/phones.css
|
135
|
-
- test/dummy/app/assets/stylesheets/application.css
|
136
124
|
- test/dummy/app/assets/javascripts/application.js
|
137
125
|
- test/dummy/app/assets/javascripts/phones.js
|
126
|
+
- test/dummy/app/helpers/phones_helper.rb
|
127
|
+
- test/dummy/app/helpers/application_helper.rb
|
128
|
+
- test/dummy/app/views/layouts/application.html.erb
|
129
|
+
- test/dummy/app/views/phones/index.html.erb
|
130
|
+
- test/dummy/app/views/phones/_form.html.erb
|
131
|
+
- test/dummy/app/views/phones/new.html.erb
|
132
|
+
- test/dummy/app/views/phones/edit.html.erb
|
133
|
+
- test/dummy/app/views/phones/show.html.erb
|
134
|
+
- test/dummy/script/rails
|
135
|
+
- test/dummy/db/development.sqlite3
|
136
|
+
- test/dummy/db/migrate/20130121173847_create_phones.rb
|
137
|
+
- test/dummy/db/migrate/20130122075331_add_possible_number_to_phone.rb
|
138
|
+
- test/dummy/db/schema.rb
|
139
|
+
- test/dummy/db/test.sqlite3
|
140
|
+
- test/dummy/config.ru
|
141
|
+
- test/dummy/README.rdoc
|
142
|
+
- test/dummy/Rakefile
|
143
|
+
- test/dummy/log/test.log
|
144
|
+
- test/dummy/log/development.log
|
145
|
+
- test/dummy/public/404.html
|
146
|
+
- test/dummy/public/422.html
|
147
|
+
- test/dummy/public/500.html
|
148
|
+
- test/dummy/public/favicon.ico
|
149
|
+
- test/dummy/test/functional/phones_controller_test.rb
|
150
|
+
- test/dummy/test/fixtures/phones.yml
|
151
|
+
- test/dummy/test/unit/helpers/phones_helper_test.rb
|
152
|
+
- test/dummy/test/unit/phone_test.rb
|
138
153
|
- test/test_helper.rb
|
139
|
-
- test/phonelib_test.rb
|
140
154
|
homepage: https://github.com/daddyz/phonelib
|
141
155
|
licenses: []
|
156
|
+
metadata: {}
|
142
157
|
post_install_message:
|
143
158
|
rdoc_options: []
|
144
159
|
require_paths:
|
145
160
|
- lib
|
146
161
|
required_ruby_version: !ruby/object:Gem::Requirement
|
147
|
-
none: false
|
148
162
|
requirements:
|
149
|
-
- -
|
163
|
+
- - '>='
|
150
164
|
- !ruby/object:Gem::Version
|
151
165
|
version: '0'
|
152
|
-
segments:
|
153
|
-
- 0
|
154
|
-
hash: 3908723268238217362
|
155
166
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
-
none: false
|
157
167
|
requirements:
|
158
|
-
- -
|
168
|
+
- - '>='
|
159
169
|
- !ruby/object:Gem::Version
|
160
170
|
version: '0'
|
161
|
-
segments:
|
162
|
-
- 0
|
163
|
-
hash: 3908723268238217362
|
164
171
|
requirements: []
|
165
172
|
rubyforge_project:
|
166
|
-
rubygems_version:
|
173
|
+
rubygems_version: 2.0.3
|
167
174
|
signing_key:
|
168
|
-
specification_version:
|
175
|
+
specification_version: 4
|
169
176
|
summary: Gem validates phone numbers with Google libphonenumber database.
|
170
177
|
test_files:
|
171
|
-
- test/
|
172
|
-
- test/dummy/
|
173
|
-
- test/dummy/
|
174
|
-
- test/dummy/db/migrate/20130122075331_add_possible_number_to_phone.rb
|
175
|
-
- test/dummy/db/development.sqlite3
|
176
|
-
- test/dummy/config.ru
|
177
|
-
- test/dummy/config/initializers/backtrace_silencers.rb
|
178
|
+
- test/phonelib_test.rb
|
179
|
+
- test/dummy/config/database.yml
|
180
|
+
- test/dummy/config/initializers/session_store.rb
|
178
181
|
- test/dummy/config/initializers/wrap_parameters.rb
|
182
|
+
- test/dummy/config/initializers/secret_token.rb
|
179
183
|
- test/dummy/config/initializers/mime_types.rb
|
184
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
180
185
|
- test/dummy/config/initializers/inflections.rb
|
181
|
-
- test/dummy/config/initializers/session_store.rb
|
182
|
-
- test/dummy/config/initializers/secret_token.rb
|
183
186
|
- test/dummy/config/environments/development.rb
|
184
|
-
- test/dummy/config/environments/production.rb
|
185
187
|
- test/dummy/config/environments/test.rb
|
186
|
-
- test/dummy/config/
|
187
|
-
- test/dummy/config/boot.rb
|
188
|
+
- test/dummy/config/environments/production.rb
|
188
189
|
- test/dummy/config/environment.rb
|
189
|
-
- test/dummy/config/routes.rb
|
190
190
|
- test/dummy/config/locales/en.yml
|
191
|
-
- test/dummy/config/
|
192
|
-
- test/dummy/
|
193
|
-
- test/dummy/
|
194
|
-
- test/dummy/public/favicon.ico
|
195
|
-
- test/dummy/public/500.html
|
196
|
-
- test/dummy/test/fixtures/phones.yml
|
197
|
-
- test/dummy/test/unit/helpers/phones_helper_test.rb
|
198
|
-
- test/dummy/test/unit/phone_test.rb
|
199
|
-
- test/dummy/test/functional/phones_controller_test.rb
|
200
|
-
- test/dummy/README.rdoc
|
201
|
-
- test/dummy/log/development.log
|
202
|
-
- test/dummy/log/test.log
|
203
|
-
- test/dummy/Rakefile
|
204
|
-
- test/dummy/script/rails
|
205
|
-
- test/dummy/app/views/layouts/application.html.erb
|
206
|
-
- test/dummy/app/views/phones/_form.html.erb
|
207
|
-
- test/dummy/app/views/phones/index.html.erb
|
208
|
-
- test/dummy/app/views/phones/show.html.erb
|
209
|
-
- test/dummy/app/views/phones/edit.html.erb
|
210
|
-
- test/dummy/app/views/phones/new.html.erb
|
191
|
+
- test/dummy/config/boot.rb
|
192
|
+
- test/dummy/config/application.rb
|
193
|
+
- test/dummy/config/routes.rb
|
211
194
|
- test/dummy/app/models/phone.rb
|
212
|
-
- test/dummy/app/helpers/application_helper.rb
|
213
|
-
- test/dummy/app/helpers/phones_helper.rb
|
214
|
-
- test/dummy/app/controllers/phones_controller.rb
|
215
195
|
- test/dummy/app/controllers/application_controller.rb
|
196
|
+
- test/dummy/app/controllers/phones_controller.rb
|
197
|
+
- test/dummy/app/assets/stylesheets/application.css
|
216
198
|
- test/dummy/app/assets/stylesheets/scaffold.css
|
217
199
|
- test/dummy/app/assets/stylesheets/phones.css
|
218
|
-
- test/dummy/app/assets/stylesheets/application.css
|
219
200
|
- test/dummy/app/assets/javascripts/application.js
|
220
201
|
- test/dummy/app/assets/javascripts/phones.js
|
202
|
+
- test/dummy/app/helpers/phones_helper.rb
|
203
|
+
- test/dummy/app/helpers/application_helper.rb
|
204
|
+
- test/dummy/app/views/layouts/application.html.erb
|
205
|
+
- test/dummy/app/views/phones/index.html.erb
|
206
|
+
- test/dummy/app/views/phones/_form.html.erb
|
207
|
+
- test/dummy/app/views/phones/new.html.erb
|
208
|
+
- test/dummy/app/views/phones/edit.html.erb
|
209
|
+
- test/dummy/app/views/phones/show.html.erb
|
210
|
+
- test/dummy/script/rails
|
211
|
+
- test/dummy/db/development.sqlite3
|
212
|
+
- test/dummy/db/migrate/20130121173847_create_phones.rb
|
213
|
+
- test/dummy/db/migrate/20130122075331_add_possible_number_to_phone.rb
|
214
|
+
- test/dummy/db/schema.rb
|
215
|
+
- test/dummy/db/test.sqlite3
|
216
|
+
- test/dummy/config.ru
|
217
|
+
- test/dummy/README.rdoc
|
218
|
+
- test/dummy/Rakefile
|
219
|
+
- test/dummy/log/test.log
|
220
|
+
- test/dummy/log/development.log
|
221
|
+
- test/dummy/public/404.html
|
222
|
+
- test/dummy/public/422.html
|
223
|
+
- test/dummy/public/500.html
|
224
|
+
- test/dummy/public/favicon.ico
|
225
|
+
- test/dummy/test/functional/phones_controller_test.rb
|
226
|
+
- test/dummy/test/fixtures/phones.yml
|
227
|
+
- test/dummy/test/unit/helpers/phones_helper_test.rb
|
228
|
+
- test/dummy/test/unit/phone_test.rb
|
221
229
|
- test/test_helper.rb
|
222
|
-
- test/phonelib_test.rb
|
data/lib/phonelib/validators.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
module Phonelib
|
2
|
-
# Module includes all ActiveModel validators classes
|
3
|
-
module Validators
|
4
|
-
# Validator class for phone validations
|
5
|
-
#
|
6
|
-
# ==== Examples
|
7
|
-
#
|
8
|
-
# Validates that attribute is a valid phone number.
|
9
|
-
# If empty value passed for attribute it fails.
|
10
|
-
#
|
11
|
-
# class Phone < ActiveRecord::Base
|
12
|
-
# attr_accessible :number
|
13
|
-
# validates :number, phone: true
|
14
|
-
# end
|
15
|
-
#
|
16
|
-
# Validates that attribute is a possible phone number.
|
17
|
-
# If empty value passed for attribute it fails.
|
18
|
-
#
|
19
|
-
# class Phone < ActiveRecord::Base
|
20
|
-
# attr_accessible :number
|
21
|
-
# validates :number, phone: { possible: true }
|
22
|
-
# end
|
23
|
-
#
|
24
|
-
# Validates that attribute is a valid phone number.
|
25
|
-
# Empty value is allowed to be passed.
|
26
|
-
#
|
27
|
-
# class Phone < ActiveRecord::Base
|
28
|
-
# attr_accessible :number
|
29
|
-
# validates :number, phone: { allow_blank: true }
|
30
|
-
# end
|
31
|
-
class PhoneValidator < ActiveModel::EachValidator
|
32
|
-
# Include all core methods
|
33
|
-
include Phonelib::Core
|
34
|
-
|
35
|
-
# Validation method
|
36
|
-
def validate_each(record, attribute, value)
|
37
|
-
phone = parse(value)
|
38
|
-
valid = options[:possible] ? phone.possible? : phone.valid?
|
39
|
-
valid = true if options[:allow_blank] && phone.original.blank?
|
40
|
-
|
41
|
-
# TODO: change to be from translations
|
42
|
-
error = "is not valid"
|
43
|
-
record.errors.add(attribute, (options[:message] || error)) unless valid
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|