phony_rails 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OGNmYjVlMTE5NDBiNGY5Y2MwZGE4ZDVlYzA2M2IxN2M1ZmI1MDBhMg==
5
+ data.tar.gz: !binary |-
6
+ ZDQ4MTIxNTdlNjVkYzNhNTZjMDQ5NWZiZDc0MTkzY2JkM2MxOWYwOQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ODIxZDY3ZDdjY2NiZGU2OGE3NzdjNzI2YzcxYzc5OGQwNGEwZTYwOTA5YWJm
10
+ MDAyZTc4Njc3NDRkZjU0ODc1NWRiYThjODUzNmI4MDljMzZiNWU1OTQ4YzNm
11
+ NDMxNGJlMjA5ZWMwMDlkOWJmOTUyNDY0NDM2Mjg0MjcwZWFhMjI=
12
+ data.tar.gz: !binary |-
13
+ MzFjNDU4OWQxNTA5ZDFkOWE4M2U5ZTNiN2FmNjE4NzE4NDMyODZlOWQ1OTc4
14
+ Y2JiMjkyYzkwMTQ5YTA1NjRhOWZlNjhmZDY0ZWU4NGUzODFkNmZkNjRkMjE3
15
+ ODA5ZWI5ZTRiOTY3MzJjNTJmNDRlNjJjMjg4MmU0MjI2OGY5NzQ=
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- phony_rails (0.4.1)
4
+ phony_rails (0.5.0)
5
5
  activesupport (>= 3.0)
6
6
  countries (>= 0.8.2)
7
- phony (>= 1.7.7)
7
+ phony (= 2.0.0)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
@@ -49,7 +49,7 @@ GEM
49
49
  moped (1.5.1)
50
50
  multi_json (1.7.9)
51
51
  origin (1.1.0)
52
- phony (1.9.0)
52
+ phony (2.0.0)
53
53
  rake (10.1.0)
54
54
  rb-fsevent (0.9.3)
55
55
  rb-inotify (0.9.1)
data/README.md CHANGED
@@ -100,6 +100,10 @@ To first normalize the String to a certain country use:
100
100
 
101
101
  <%= "010-12341234".phony_formatted(:normalize => :NL, :format => :international, :spaces => '-') %>
102
102
 
103
+ To return nil when a number is not valid:
104
+
105
+ "123".phony_formatted(:strict => true) # => nil
106
+
103
107
  You can also use the bang method (phony_formatted!):
104
108
 
105
109
  number = "010-12341234"
@@ -114,6 +118,9 @@ Say you want to find a record by a phone number. Best is to normalize user input
114
118
 
115
119
  ## Changelog
116
120
 
121
+ 0.5.0
122
+ * Added :strict option to String#phony_formatted.
123
+
117
124
  0.4.2
118
125
  * Added @fareastside validation for country_code.
119
126
 
data/lib/phony_rails.rb CHANGED
@@ -7,7 +7,7 @@ require 'phony_rails/version'
7
7
  module PhonyRails
8
8
 
9
9
  def self.country_number_for(country_code)
10
- ISO3166::Country::Data[country_code].try(:[], 'country_code')
10
+ ISO3166::Country::Data[country_code.to_s.upcase].try(:[], 'country_code')
11
11
  end
12
12
 
13
13
  # This method requires a country_code attribute (eg. NL) and phone_number to be set.
@@ -6,10 +6,13 @@
6
6
  # "31612341234".phony_formatted(:spaces => '-') # => '06-12341234'
7
7
  # To first normalize a String use:
8
8
  # "010-12341234".phony_formatted(:normalize => :NL)
9
+ # To return nil when a number is not correct (checked using Phony.plausible?) use
10
+ # "010-12341234".phony_formatted(strict: true)
9
11
  def phony_formatted(options = {})
10
12
  normalize_country_code = options.delete(:normalize)
11
13
  s = (normalize_country_code ? PhonyRails.normalize_number(self, :default_country_code => normalize_country_code.to_s) : self.gsub(/\D/, ''))
12
14
  return if s.blank?
15
+ return if options[:strict] && !Phony.plausible?(s)
13
16
  Phony.formatted(s, options.reverse_merge(:format => :national))
14
17
  end
15
18
 
@@ -1,3 +1,3 @@
1
1
  module PhonyRails
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.0"
3
3
  end
data/phony_rails.gemspec CHANGED
@@ -7,6 +7,7 @@ Gem::Specification.new do |gem|
7
7
  gem.description = %q{This Gem adds useful methods to your Rails app to validate, display and save phone numbers.}
8
8
  gem.summary = %q{This Gem adds useful methods to your Rails app to validate, display and save phone numbers.}
9
9
  gem.homepage = "https://github.com/joost/phony_rails"
10
+ gem.license = 'MIT'
10
11
 
11
12
  gem.files = `git ls-files`.split($\)
12
13
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -15,7 +16,7 @@ Gem::Specification.new do |gem|
15
16
  gem.require_paths = ["lib"]
16
17
  gem.version = PhonyRails::VERSION
17
18
 
18
- gem.add_dependency "phony", ">= 1.7.7"
19
+ gem.add_dependency "phony", "= 1.9.0"
19
20
  gem.add_dependency "countries", ">= 0.8.2"
20
21
  gem.add_dependency "activesupport", ">= 3.0"
21
22
  gem.add_development_dependency "activerecord", ">= 3.0"
@@ -17,6 +17,22 @@ describe PhonyRails do
17
17
 
18
18
  end
19
19
 
20
+ describe 'with strict option' do
21
+
22
+ it "should return nil with non plausible number" do
23
+ number = '+319090' # not valid
24
+ Phony.plausible?(number).should be_false
25
+ number.phony_formatted(:strict => true).should eql(nil)
26
+ end
27
+
28
+ it "should not return nil with plausible number" do
29
+ number = '+31101234123' # valid
30
+ Phony.plausible?(number).should be_true
31
+ number.phony_formatted(:strict => true).should_not eql(nil)
32
+ end
33
+
34
+ end
35
+
20
36
  describe 'with normalize option' do
21
37
 
22
38
  it "should phony_format" do
@@ -48,6 +64,15 @@ describe PhonyRails do
48
64
 
49
65
  end
50
66
 
67
+ describe "specific tests from issues" do
68
+
69
+ # https://github.com/joost/phony_rails/issues/42
70
+ it "should pass issue Github issue #42" do
71
+ PhonyRails.normalize_number("0606060606", default_country_code: 'FR').should eq('33606060606')
72
+ end
73
+
74
+ end
75
+
51
76
  it "should not change original String" do
52
77
  s = "0101234123"
53
78
  s.phony_formatted(:normalize => :NL).should eql('010 1234123')
@@ -86,6 +111,10 @@ describe PhonyRails do
86
111
  PhonyRails.normalize_number('4790909090', :country_code => 'SE').should eql('464790909090')
87
112
  end
88
113
 
114
+ it "should recognize lowercase country codes" do
115
+ PhonyRails.normalize_number('4790909090', :country_code => 'se').should eql('464790909090')
116
+ end
117
+
89
118
  end
90
119
 
91
120
  context 'number without a country code' do
@@ -108,6 +137,10 @@ describe PhonyRails do
108
137
  PhonyRails.normalize_number('(030) 8 61 29 06', :country_code => 'DE', :default_country_code => 'NL').should eql('49308612906')
109
138
  end
110
139
 
140
+ it "should recognize lowercase country codes" do
141
+ PhonyRails.normalize_number('010-1234123', :country_code => 'nl').should eql('31101234123')
142
+ end
143
+
111
144
  end
112
145
 
113
146
  it "should handle some edge cases" do
metadata CHANGED
@@ -1,36 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phony_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
5
- prerelease:
4
+ version: 0.5.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Joost Hietbrink
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-08-28 00:00:00.000000000 Z
11
+ date: 2013-12-24 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: phony
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '='
20
18
  - !ruby/object:Gem::Version
21
- version: 1.7.7
19
+ version: 1.9.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '='
28
25
  - !ruby/object:Gem::Version
29
- version: 1.7.7
26
+ version: 1.9.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: countries
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: activesupport
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ! '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ! '>='
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: activerecord
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ! '>='
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ! '>='
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: mongoid
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ! '>='
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ! '>='
92
81
  - !ruby/object:Gem::Version
@@ -119,32 +108,31 @@ files:
119
108
  - spec/lib/validators/phony_validator_spec.rb
120
109
  - spec/spec_helper.rb
121
110
  homepage: https://github.com/joost/phony_rails
122
- licenses: []
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
123
114
  post_install_message:
124
115
  rdoc_options: []
125
116
  require_paths:
126
117
  - lib
127
118
  required_ruby_version: !ruby/object:Gem::Requirement
128
- none: false
129
119
  requirements:
130
120
  - - ! '>='
131
121
  - !ruby/object:Gem::Version
132
122
  version: '0'
133
123
  required_rubygems_version: !ruby/object:Gem::Requirement
134
- none: false
135
124
  requirements:
136
125
  - - ! '>='
137
126
  - !ruby/object:Gem::Version
138
127
  version: '0'
139
128
  requirements: []
140
129
  rubyforge_project:
141
- rubygems_version: 1.8.25
130
+ rubygems_version: 2.1.11
142
131
  signing_key:
143
- specification_version: 3
132
+ specification_version: 4
144
133
  summary: This Gem adds useful methods to your Rails app to validate, display and save
145
134
  phone numbers.
146
135
  test_files:
147
136
  - spec/lib/phony_rails_spec.rb
148
137
  - spec/lib/validators/phony_validator_spec.rb
149
138
  - spec/spec_helper.rb
150
- has_rdoc: