phony_rails 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- phony_rails (0.1.0)
4
+ phony_rails (0.1.2)
5
5
  activerecord (~> 3.0)
6
+ countries (~> 0.8.2)
6
7
  phony (~> 1.7.4)
7
8
 
8
9
  GEM
@@ -21,6 +22,10 @@ GEM
21
22
  multi_json (~> 1.0)
22
23
  arel (3.0.2)
23
24
  builder (3.0.0)
25
+ countries (0.8.2)
26
+ currencies (= 0.4.0)
27
+ currencies (>= 0.2.0)
28
+ currencies (0.4.0)
24
29
  diff-lcs (1.1.3)
25
30
  i18n (0.6.0)
26
31
  multi_json (1.3.6)
data/README.md CHANGED
@@ -34,7 +34,7 @@ PhonyRails will also check your model for a country_code method to use when norm
34
34
 
35
35
  Use the Phony.plausible method to validate an attribute:
36
36
 
37
- validate :phone_number, :phony_plausible => true
37
+ validates :phone_number, :phony_plausible => true
38
38
 
39
39
  In your views use:
40
40
 
@@ -42,6 +42,10 @@ In your views use:
42
42
 
43
43
  ## Changelog
44
44
 
45
+ 0.1.2
46
+ * Using countries gem as suggested by brutuscat.
47
+ * Fixes bugs mentioned by ddidier.
48
+
45
49
  0.1.0
46
50
  * Added specs.
47
51
 
@@ -1,26 +1,14 @@
1
1
  require 'phony'
2
- require "phony_rails/string_extensions"
3
- require "phony_rails/version"
2
+ require 'countries'
3
+ require 'phony_rails/string_extensions'
4
+ require 'validators/phony_validator'
5
+ require 'phony_rails/version'
4
6
 
5
7
  module PhonyRails
6
8
 
7
- # Quick fix to get country_phone_number (phone number) for all relevant countries.
8
- # TODO: Replace with some gem or something.
9
- COUNTRY_NUMBER = {
10
- 'NL' => '31',
11
- 'BE' => '32',
12
- 'DE' => '49',
13
- 'GB' => '44',
14
- 'FR' => '33',
15
- 'ES' => '34',
16
- 'IT' => '39',
17
- 'US' => '1',
18
- 'AU' => '61',
19
- 'LU' => '352',
20
- 'AT' => '43',
21
- 'CH' => '41',
22
- 'PL' => '48'
23
- }
9
+ def self.country_number_for(country_code)
10
+ ISO3166::Country::Data[country_code].try(:[], 'country_code')
11
+ end
24
12
 
25
13
  # This method requires a country_code attribute (eg. NL) and phone_number to be set.
26
14
  # Options:
@@ -33,14 +21,14 @@ module PhonyRails
33
21
  number = number.clone # Just to be sure, we don't want to change the original.
34
22
  number.gsub!(/[^\d\+]/, '') # Strips weird stuff from the number
35
23
  return if number.blank?
36
- if country_number = COUNTRY_NUMBER[options[:country_code] || options[:default_country_code]]
24
+ if country_number = country_number_for(options[:country_code] || options[:default_country_code])
37
25
  # Add country_number if missing
38
26
  number = "#{country_number}#{number}" if not number =~ /^(00|\+)?#{country_number}/
39
27
  end
40
28
  number = Phony.normalize(number)
41
29
  return number.to_s
42
- rescue
43
- number # If all goes wrong .. we still return the original input.
30
+ # rescue
31
+ # number # If all goes wrong .. we still return the original input.
44
32
  end
45
33
 
46
34
  # This module is added to AR.
@@ -1,3 +1,3 @@
1
1
  module PhonyRails
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
6
6
  gem.email = ["joost@joopp.com"]
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
- gem.homepage = ""
9
+ gem.homepage = "https://github.com/joost/phony_rails"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
12
12
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -16,5 +16,6 @@ Gem::Specification.new do |gem|
16
16
  gem.version = PhonyRails::VERSION
17
17
 
18
18
  gem.add_dependency "phony", "~> 1.7.4"
19
+ gem.add_dependency "countries", "~> 0.8.2"
19
20
  gem.add_dependency "activerecord", "~> 3.0"
20
21
  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.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: 1.7.4
30
+ - !ruby/object:Gem::Dependency
31
+ name: countries
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.8.2
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.8.2
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: activerecord
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -63,7 +79,7 @@ files:
63
79
  - phony_rails.gemspec
64
80
  - spec/lib/phony_rails_spec.rb
65
81
  - spec/spec_helper.rb
66
- homepage: ''
82
+ homepage: https://github.com/joost/phony_rails
67
83
  licenses: []
68
84
  post_install_message:
69
85
  rdoc_options: []