phony_rails 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- phony_rails (0.2.2)
4
+ phony_rails (0.3.0)
5
5
  activerecord (>= 3.0)
6
6
  countries (>= 0.8.2)
7
7
  phony (>= 1.7.7)
data/lib/phony_rails.rb CHANGED
@@ -12,6 +12,8 @@ module PhonyRails
12
12
 
13
13
  # This method requires a country_code attribute (eg. NL) and phone_number to be set.
14
14
  # Options:
15
+ # :country_number => The country dial code (eg. 31 for NL).
16
+ # :default_country_number => Fallback country code.
15
17
  # :country_code => The country code we should use.
16
18
  # :default_country_code => Some fallback code (eg. 'NL') that can be used as default (comes from phony_normalize_numbers method).
17
19
  # This idea came from:
@@ -21,12 +23,12 @@ module PhonyRails
21
23
  number = number.clone # Just to be sure, we don't want to change the original.
22
24
  number.gsub!(/[^\d\+]/, '') # Strips weird stuff from the number
23
25
  return if number.blank?
24
- if country_number = country_number_for(options[:country_code])
26
+ if country_number = options[:country_number] || country_number_for(options[:country_code])
25
27
  # (Force) add country_number if missing
26
28
  number = "#{country_number}#{number}" if not number =~ /^(00|\+)?#{country_number}/
27
- elsif default_country_number = country_number_for(options[:default_country_code])
29
+ elsif default_country_number = options[:default_country_number] || country_number_for(options[:default_country_code])
28
30
  # Add default_country_number if missing
29
- number = "#{default_country_number}#{number}" if not number =~ /^(00|\+)/
31
+ number = "#{default_country_number}#{number}" if not number =~ /^(00|\+|#{default_country_number})/
30
32
  end
31
33
  number = Phony.normalize(number) if Phony.plausible?(number)
32
34
  return number.to_s
@@ -1,3 +1,3 @@
1
1
  module PhonyRails
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -72,10 +72,14 @@ describe PhonyRails do
72
72
 
73
73
  it "should not add default_country_code" do
74
74
  PhonyRails.normalize_number('+4790909090', :default_country_code => 'SE').should eql('4790909090') # SE = +46
75
+ PhonyRails.normalize_number('004790909090', :default_country_code => 'SE').should eql('4790909090')
76
+ PhonyRails.normalize_number('4790909090', :default_country_code => 'NO').should eql('4790909090') # NO = +47
75
77
  end
76
78
 
77
79
  it "should force add country_code" do
78
80
  PhonyRails.normalize_number('+4790909090', :country_code => 'SE').should eql('464790909090')
81
+ PhonyRails.normalize_number('004790909090', :country_code => 'SE').should eql('464790909090')
82
+ PhonyRails.normalize_number('4790909090', :country_code => 'SE').should eql('464790909090')
79
83
  end
80
84
 
81
85
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phony_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-06 00:00:00.000000000 Z
12
+ date: 2013-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: phony