phone 1.2.3 → 1.3.0.beta0

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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.document +3 -0
  3. data/.gitignore +5 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +14 -0
  6. data/.yardopts +1 -0
  7. data/ChangeLog.md +50 -0
  8. data/Gemfile +11 -0
  9. data/LICENSE.txt +22 -0
  10. data/README.md +183 -0
  11. data/Rakefile +38 -0
  12. data/data/{phone_countries.yml → phone/countries.yml} +16 -14
  13. data/lib/phone.rb +75 -53
  14. data/lib/phone/country.rb +45 -0
  15. data/lib/{errors.rb → phone/errors.rb} +0 -0
  16. data/lib/phone/version.rb +4 -0
  17. data/phone.gemspec +25 -0
  18. data/test/countries/au_test.rb +11 -11
  19. data/test/countries/ba_test.rb +4 -4
  20. data/test/countries/be_test.rb +12 -11
  21. data/test/countries/de_test.rb +7 -7
  22. data/test/countries/es_test.rb +33 -0
  23. data/test/countries/fr_test.rb +5 -5
  24. data/test/countries/gb_test.rb +42 -41
  25. data/test/countries/hr_test.rb +14 -14
  26. data/test/countries/hu_test.rb +5 -5
  27. data/test/countries/ie_test.rb +20 -0
  28. data/test/countries/nl_test.rb +43 -43
  29. data/test/countries/nz_test.rb +8 -0
  30. data/test/countries/pt_test.rb +18 -18
  31. data/test/countries/rs_test.rb +7 -7
  32. data/test/countries/se_test.rb +44 -43
  33. data/test/countries/si_test.rb +7 -7
  34. data/test/countries/ua_test.rb +4 -4
  35. data/test/countries/us_test.rb +6 -6
  36. data/test/countries/uy_test.rb +22 -0
  37. data/test/countries/za_test.rb +4 -4
  38. data/test/extension_test.rb +3 -3
  39. data/test/helper.rb +41 -0
  40. data/test/phone_test.rb +99 -53
  41. data/test_usa_phones_with_extensions.csv +99 -0
  42. metadata +112 -30
  43. data/LICENSE +0 -19
  44. data/Readme.rdoc +0 -126
  45. data/lib/country.rb +0 -36
  46. data/lib/support.rb +0 -78
  47. data/test/test_helper.rb +0 -15
metadata CHANGED
@@ -1,76 +1,154 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phone
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.3.0.beta0
5
5
  platform: ruby
6
6
  authors:
7
- - Tomislav Car
7
+ - Tomislav Carr
8
8
  - Todd Eichel
9
9
  - Don Morrison
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-11-16 00:00:00.000000000 Z
14
- dependencies: []
15
- description: Phone number parsing, validation and formatting.
13
+ date: 2014-04-27 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.2'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ version: '1.2'
29
+ - !ruby/object:Gem::Dependency
30
+ name: minitest
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: '5.0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ version: '5.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rake
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: '10.0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: '10.0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: rubygems-tasks
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ version: '0.2'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: '0.2'
71
+ - !ruby/object:Gem::Dependency
72
+ name: yard
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '0.8'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ~>
83
+ - !ruby/object:Gem::Version
84
+ version: '0.8'
85
+ description: Phone number parsing, validation and formatting in Ruby
16
86
  email:
17
87
  - tomislav@infinum.hr
18
88
  - todd@toddeichel.com
19
- - elskwid@gmail.com
89
+ - don@elskwid.net
20
90
  executables: []
21
91
  extensions: []
22
- extra_rdoc_files:
23
- - Readme.rdoc
24
- - LICENSE
92
+ extra_rdoc_files: []
25
93
  files:
26
- - Readme.rdoc
27
- - LICENSE
28
- - data/phone_countries.yml
94
+ - .document
95
+ - .gitignore
96
+ - .ruby-version
97
+ - .travis.yml
98
+ - .yardopts
99
+ - ChangeLog.md
100
+ - Gemfile
101
+ - LICENSE.txt
102
+ - README.md
103
+ - Rakefile
104
+ - data/phone/countries.yml
29
105
  - lib/phone.rb
30
- - lib/country.rb
31
- - lib/errors.rb
32
- - lib/support.rb
33
- - test/extension_test.rb
34
- - test/phone_test.rb
35
- - test/test_helper.rb
106
+ - lib/phone/country.rb
107
+ - lib/phone/errors.rb
108
+ - lib/phone/version.rb
109
+ - phone.gemspec
36
110
  - test/countries/au_test.rb
37
111
  - test/countries/ba_test.rb
38
112
  - test/countries/be_test.rb
39
113
  - test/countries/de_test.rb
114
+ - test/countries/es_test.rb
40
115
  - test/countries/fr_test.rb
41
116
  - test/countries/gb_test.rb
42
117
  - test/countries/hr_test.rb
43
118
  - test/countries/hu_test.rb
119
+ - test/countries/ie_test.rb
44
120
  - test/countries/nl_test.rb
121
+ - test/countries/nz_test.rb
45
122
  - test/countries/pt_test.rb
46
123
  - test/countries/rs_test.rb
47
124
  - test/countries/se_test.rb
48
125
  - test/countries/si_test.rb
49
126
  - test/countries/ua_test.rb
50
127
  - test/countries/us_test.rb
128
+ - test/countries/uy_test.rb
51
129
  - test/countries/za_test.rb
52
- homepage: http://github.com/carr/phone
130
+ - test/extension_test.rb
131
+ - test/helper.rb
132
+ - test/phone_test.rb
133
+ - test_usa_phones_with_extensions.csv
134
+ homepage: https://github.com/carr/phone#readme
53
135
  licenses:
54
136
  - MIT
55
137
  metadata: {}
56
138
  post_install_message:
57
- rdoc_options:
58
- - "--main"
59
- - Readme.rdoc
60
- - "--inline-source"
61
- - "--charset=UTF-8"
139
+ rdoc_options: []
62
140
  require_paths:
63
141
  - lib
64
142
  required_ruby_version: !ruby/object:Gem::Requirement
65
143
  requirements:
66
- - - ">="
144
+ - - '>='
67
145
  - !ruby/object:Gem::Version
68
146
  version: '0'
69
147
  required_rubygems_version: !ruby/object:Gem::Requirement
70
148
  requirements:
71
- - - ">="
149
+ - - '>'
72
150
  - !ruby/object:Gem::Version
73
- version: '0'
151
+ version: 1.3.1
74
152
  requirements: []
75
153
  rubyforge_project:
76
154
  rubygems_version: 2.0.3
@@ -78,22 +156,26 @@ signing_key:
78
156
  specification_version: 4
79
157
  summary: Phone number parsing, validation and formatting
80
158
  test_files:
81
- - test/extension_test.rb
82
- - test/phone_test.rb
83
- - test/test_helper.rb
84
159
  - test/countries/au_test.rb
85
160
  - test/countries/ba_test.rb
86
161
  - test/countries/be_test.rb
87
162
  - test/countries/de_test.rb
163
+ - test/countries/es_test.rb
88
164
  - test/countries/fr_test.rb
89
165
  - test/countries/gb_test.rb
90
166
  - test/countries/hr_test.rb
91
167
  - test/countries/hu_test.rb
168
+ - test/countries/ie_test.rb
92
169
  - test/countries/nl_test.rb
170
+ - test/countries/nz_test.rb
93
171
  - test/countries/pt_test.rb
94
172
  - test/countries/rs_test.rb
95
173
  - test/countries/se_test.rb
96
174
  - test/countries/si_test.rb
97
175
  - test/countries/ua_test.rb
98
176
  - test/countries/us_test.rb
177
+ - test/countries/uy_test.rb
99
178
  - test/countries/za_test.rb
179
+ - test/extension_test.rb
180
+ - test/helper.rb
181
+ - test/phone_test.rb
data/LICENSE DELETED
@@ -1,19 +0,0 @@
1
- Copyright (c) 2010 Tomislav Car
2
- Modifications copyright (c) 2010 Todd Eichel for Fooala, Inc.
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of
5
- this software and associated documentation files (the "Software"), to deal in
6
- the Software without restriction, including without limitation the rights to
7
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
- the Software, and to permit persons to whom the Software is furnished to do so,
9
- subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in all
12
- copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,126 +0,0 @@
1
- = Phone
2
- Parsing, validating and creating phone numbers
3
-
4
- == Install
5
- You can install the phone library as a gem
6
- gem sources -a http://gemcutter.org
7
- gem install phone
8
-
9
- Or as a Rails plugin
10
- script/plugin install git://github.com/carr/phone.git
11
-
12
- == Updates in v 1.0
13
-
14
- The biggest updating is the namespacing problem fixed that a lot of people were having. You now use phone by refering to
15
-
16
- Phoner::Phone
17
-
18
- == Initializing
19
- You can initialize a new phone object with the number, area code, country code and extension number
20
-
21
- Phoner::Phone.new('5125486', '91', '385')
22
- or
23
- Phoner::Phone.new(:number => '5125486', :area_code => '91', :country_code => '385', :extension => '143')
24
-
25
- == Parsing
26
- You can create a new phone object by parsing from a string. Phoner::Phone does it's best to detect the country and area codes:
27
- Phoner::Phone.parse '+385915125486'
28
- Phoner::Phone.parse '00385915125486'
29
-
30
- If the country or area code isn't given in the string, you must set it, otherwise it doesn't work:
31
- Phoner::Phone.parse '091/512-5486', :country_code => '385'
32
- Phoner::Phone.parse '(091) 512 5486', :country_code => '385'
33
-
34
- If you feel that it's tedious, set the default country code once (in your config/environment.rb):
35
- Phoner::Phone.default_country_code = '385'
36
- Phoner::Phone.parse '091/512-5486'
37
- Phoner::Phone.parse '(091) 512 5486'
38
-
39
- Same goes for the area code:
40
- Phoner::Phone.parse '451-588', :country_code => '385', :area_code => '47'
41
- or
42
- Phoner::Phone.default_country_code = '385'
43
- Phoner::Phone.default_area_code = '47'
44
-
45
- Phoner::Phone.parse '451-588'
46
-
47
- === Automatic country and area code detection
48
- Like it's stated above, Phone does it's best to automatically detect the country and area code while parsing. Do do this,
49
- phone uses data stored in <tt>data/countries.yml</tt>.
50
-
51
- Each country code can have a regular expression named <tt>area_code</tt> that describes how the area code for that
52
- particular country looks like.
53
-
54
- If an <tt>area_code</tt> regular expression isn't specified, the default, <tt>Phoner::Phone::DEFAULT_AREA_CODE</tt> (correct for
55
- the US) is used.
56
-
57
- == Validating
58
- Validating is very relaxed, basically it strips out everything that's not a number or '+' character:
59
- Phoner::Phone.valid? 'blabla 091/512-5486 blabla'
60
-
61
- == Formatting
62
- Formating is done via the <tt>format</tt> method. The method accepts a <tt>Symbol</tt> or a <tt>String</tt>.
63
-
64
- When given a string, it interpolates the string with the following fields:
65
-
66
- * %c - country_code (385)
67
- * %a - area_code (91)
68
- * %A - area_code with leading zero (091)
69
- * %n - number (5125486)
70
- * %f - first @@n1_length characters of number (configured through Phoner::Phone.n1_length), default is 3 (512)
71
- * %l - last characters of number (5486)
72
- * %x - the extension number
73
-
74
- pn = Phoner::Phone.parse('+385915125486')
75
- pn.to_s # => "+385915125486"
76
- pn.format("%A/%f-%l") # => "091/512-5486"
77
- pn.format("+ %c (%a) %n") # => "+ 385 (91) 5125486"
78
-
79
- When given a symbol it is used as a lookup for the format in the <tt>Phoner::Phone.named_formats</tt> hash.
80
- pn.format(:europe) # => "+385 (0) 91 512 5486"
81
- pn.format(:us) # => "(234) 123 4567"
82
- pn.format(:default_with_extension) # => "+3851234567x143"
83
-
84
- You can add your own custom named formats like so:
85
- Phoner::Phone.named_formats[:short] = '%A/%n1-%n2'
86
- pn.format(:short) # => 091/512-5486
87
-
88
- == Finding countries by their isocode
89
- If you don't have the country code, but you know from other sources what country a phone is from, you can retrieve the country using the country isocode (such as 'de', 'es', 'us', ...).
90
-
91
- if country = Phoner::Country.find_by_country_isocode(user_country_isocode)
92
- phone_number = Phoner::Phone.parse(user_input, :country_code => country.country_code)
93
- end
94
-
95
- You have to remember to run Phoner::Country.load method before though.
96
-
97
- = TODO
98
- Parse testing for different countries.
99
-
100
- Currently tested on:
101
- [AU] Australia
102
- [BA] Bosnia and Herzegovina
103
- [BE] Belgium
104
- [DE] Germany
105
- [ES] Spain
106
- [FR] France
107
- [GB] United Kingdom
108
- [HR] Croatia
109
- [HU] Hungary
110
- [NL] Netherlands
111
- [RS] Serbia
112
- [SE] Sweden
113
- [SI] Slovenia
114
- [UA] Ukraine
115
- [US] United States
116
- [ZA] South Africa
117
-
118
- = Known issues
119
- There's an issue with Germany and Spanish area codes.
120
-
121
- = Author
122
- Copyright © 2010 Tomislav Car, {Infinum}[http://www.infinumdigital.com]
123
-
124
- = Contributors
125
- Don Morrison, Michael Squires, Todd Eichel (Fooala, Inc.), chipiga, Etienne Samson, Luke Randall, Jakob Hilden, Tieg Zaharia
126
-
@@ -1,36 +0,0 @@
1
- module Phoner
2
- class Country < Struct.new(:name, :country_code, :char_2_code, :char_3_code, :area_code)
3
- cattr_accessor :all
4
-
5
- def self.load
6
- return @@all if @@all.present?
7
-
8
- data_file = File.join(File.dirname(__FILE__), '..', 'data', 'phone_countries.yml')
9
-
10
- @@all = {}
11
- YAML.load(File.read(data_file)).each_pair do |key, c|
12
- @@all[key] = Country.new(c[:name], c[:country_code], c[:char_2_code], c[:char_3_code], c[:area_code])
13
- end
14
- @@all
15
- end
16
-
17
- def to_s
18
- name
19
- end
20
-
21
- def self.find_by_country_code(code)
22
- @@all[code]
23
- end
24
-
25
- def self.find_by_country_isocode(isocode)
26
- if country = @@all.detect{|c|c[1].char_3_code.downcase == isocode}
27
- country[1]
28
- end
29
- end
30
-
31
- def country_code_regexp
32
- Regexp.new("^[+]#{country_code}")
33
- end
34
- end
35
-
36
- end
@@ -1,78 +0,0 @@
1
- require 'yaml'
2
- # support methods to remove dependencies on ActiveSupport
3
- class String
4
- def present?
5
- !blank?
6
- end
7
-
8
- def blank?
9
- if respond_to?(:empty?) && respond_to?(:strip)
10
- empty? or strip.empty?
11
- elsif respond_to?(:empty?)
12
- empty?
13
- else
14
- !self
15
- end
16
- end
17
- end
18
-
19
- class Hash
20
- alias_method :blank?, :empty?
21
-
22
- def present?
23
- !blank?
24
- end
25
- end
26
-
27
- class Object
28
- def present?
29
- self.class!=NilClass
30
- end
31
- end
32
-
33
- class NilClass #:nodoc:
34
- def blank?
35
- true
36
- end
37
-
38
- def present?
39
- false
40
- end
41
- end
42
-
43
- module Accessorize
44
- module ClassMethods
45
- def cattr_accessor(*syms)
46
- syms.flatten.each do |sym|
47
- class_eval(<<-EOS, __FILE__, __LINE__)
48
- unless defined? @@#{sym}
49
- @@#{sym} = nil
50
- end
51
-
52
- def self.#{sym}
53
- @@#{sym}
54
- end
55
-
56
- def #{sym}=(value)
57
- @@#{sym} = value
58
- end
59
-
60
- def self.#{sym}=(value)
61
- @@#{sym} = value
62
- end
63
-
64
- def #{sym}
65
- @@#{sym}
66
- end
67
- EOS
68
- end
69
- end
70
- end
71
-
72
-
73
- def self.included(receiver)
74
- receiver.extend ClassMethods
75
- end
76
- end
77
-
78
- Object.send(:include, Accessorize)