phony 1.6.6 → 1.6.7

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.
data/lib/phony.rb CHANGED
@@ -39,8 +39,8 @@ module Phony
39
39
 
40
40
  # Phony uses a single country codes instance.
41
41
  #
42
- @codes = CountryCodes.instance
43
- @validator = Validators.instance
42
+ @codes = CountryCodes.instance
43
+ @validators = Validators.instance
44
44
 
45
45
  class << self
46
46
 
@@ -85,7 +85,7 @@ module Phony
85
85
  # leaning towards being plausible.
86
86
  #
87
87
  def plausible? number, hints = {}
88
- @validator.plausible? number, hints
88
+ @validators.plausible? number, hints
89
89
  end
90
90
 
91
91
  # def service? number
@@ -17,6 +17,10 @@
17
17
  # * matched_split: Give a hash of regex => format array, with a :fallback => format option.
18
18
  # (See Norway how it looks.)
19
19
  #
20
+ # The third parameter to country are validations.
21
+ # Currently, there is one method available:
22
+ # * invalid_ndcs: Give a regexp or string to describe invalid ndc(s).
23
+ #
20
24
  # Note: The ones that are commented are defined in their special files.
21
25
  #
22
26
  Phony.define do
@@ -29,7 +33,7 @@ Phony.define do
29
33
  #
30
34
  country '1',
31
35
  fixed(3) >> split(3,4),
32
- invalid_ndcs(/911/)
36
+ invalid_ndcs('911') # /911/ would also work.
33
37
 
34
38
  # Kazakhstan (Republic of) & Russian Federation.
35
39
  #
@@ -26,7 +26,7 @@ module Phony
26
26
  def clean number
27
27
  # Remove non-digit chars.
28
28
  #
29
- number.gsub! @@basic_normalizing_pattern, EMPTY_STRING
29
+ number.gsub!(@@basic_normalizing_pattern, EMPTY_STRING) || number
30
30
  end
31
31
  def normalize number
32
32
  clean number
@@ -49,12 +49,12 @@ module Phony
49
49
  # CC.
50
50
  #
51
51
  cc_needed = hints[:cc]
52
- return false if cc_needed && cc_needed != cc
52
+ return false if cc_needed && !(cc_needed === cc)
53
53
 
54
54
  # NDC.
55
55
  #
56
56
  ndc_needed = hints[:ndc]
57
- return false if ndc_needed && ndc_needed != ndc
57
+ return false if ndc_needed && !(ndc_needed === ndc)
58
58
 
59
59
  # Country specific checks.
60
60
  #
@@ -28,12 +28,47 @@ describe 'validations' do
28
28
  it "is correct for explicit checks" do
29
29
  Phony.plausible?('+41 44 111 22 33', ndc: '43').should be_false
30
30
  end
31
+ it "is correct for explicit checks" do
32
+ Phony.plausible?('+41 44 111 22 33', cc: '41', ndc: '44').should be_true
33
+ end
34
+ it "works with regexps" do
35
+ Phony.plausible?('+41 44 111 22 33', cc: /4(0|2)/, ndc: /4(4|5)/).should be_false
36
+ end
37
+ it "works with regexps" do
38
+ Phony.plausible?('+41 44 111 22 33', cc: /4(0|1)/, ndc: /4(4|5)/).should be_true
39
+ end
31
40
 
32
- context 'countries' do
41
+ context 'specific countries' do
42
+
43
+ # TODO
44
+ #
45
+ # it "is correct for Swiss numbers" do
46
+ # Phony.plausible?('+41 44 111 22 33').should be_true
47
+ # end
33
48
 
34
49
  it "is correct for US numbers" do
50
+ # Sorry, still need E164 conform numbers.
51
+ #
52
+ Phony.plausible?('4346667777', cc: '1').should be_false
53
+
54
+ # Automatic country checking.
55
+ #
56
+ Phony.plausible?('1-4346667777').should be_true
35
57
  Phony.plausible?('1-800-692-7753').should be_true
36
58
  Phony.plausible?('1-911').should be_false
59
+ Phony.plausible?('1-911-123-1234').should be_false
60
+
61
+ # With string constraints.
62
+ #
63
+ Phony.plausible?('14346667777', cc: '1').should be_true
64
+ Phony.plausible?('14346667777', ndc: '434').should be_true
65
+ Phony.plausible?('14346667777', cc: '1', ndc: '434').should be_true
66
+
67
+ # With regexp constraints.
68
+ #
69
+ Phony.plausible?('14346667777', cc: /[123]/).should be_true
70
+ Phony.plausible?('14346667777', ndc: /434|435/).should be_true
71
+ Phony.plausible?('14346667777', cc: /[123]/, ndc: /434|435/).should be_true
37
72
  end
38
73
 
39
74
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phony
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.6
4
+ version: 1.6.7
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: 2012-03-18 00:00:00.000000000 Z
12
+ date: 2012-03-20 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! 'Fast international phone number (E164 standard) normalizing, splitting
15
15
  and formatting. Lots of formatting options: International (+.., 00..), national