cold_shoulder 1.2.0 → 1.2.1
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.
- checksums.yaml +4 -4
- data/lib/validator.rb +18 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e39b4d0880880293156ef14b3a250f1d15f4f07a
|
4
|
+
data.tar.gz: 3200be955fde4a5a3e25e7a5c6ffd8b6c994bec5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 876e89ec45c6f4336b90c83b16c2548b7232b72e3eec40cf1a764fa88ab91f206113809dcae743e0de86b34eeb359b2e487f24c73a25569333a7cb8d6b4fd3fd
|
7
|
+
data.tar.gz: 057dc821f926bab1603de78919964ab58852b510950ad10e11ba37e85d77870fe847a4b107be586a395fc74316f8da23b866bbbebbe7f12f814ab16653911625
|
data/lib/validator.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# require 'damerau-levenshtein'
|
2
|
+
|
1
3
|
# For monkeypatch
|
2
4
|
require 'active_model'
|
3
5
|
require 'active_model/validations'
|
@@ -22,14 +24,19 @@ module ActiveModel
|
|
22
24
|
EMAIL_REGEX = /(\b[^\s]+?\s*(@|at)\s*[^\s]+?\.[^\s]+?\b)/i
|
23
25
|
URL_REGEX = /\b(\S+?\.\S+?)\b/i
|
24
26
|
|
27
|
+
NUMBER_WORDS = {one: 1, two: 2, three: 3,
|
28
|
+
four: 4, five: 5, six: 6, seven: 7,
|
29
|
+
eight: 9, nine: 9, zero: 0, oh: 0}
|
30
|
+
|
25
31
|
def initialize(options)
|
26
32
|
options[:ignore_link] = true if options[:remove_links]
|
27
|
-
|
28
33
|
super
|
29
34
|
end
|
30
35
|
|
31
36
|
def validate_each(record, attr_name, value)
|
32
37
|
|
38
|
+
value = convert_numbers_at_words_in(value) unless options[:ignore_number_words]
|
39
|
+
|
33
40
|
# Detect any contact methods in the value
|
34
41
|
detected = detect_contacts_in value
|
35
42
|
|
@@ -91,6 +98,16 @@ module ActiveModel
|
|
91
98
|
return errors
|
92
99
|
end
|
93
100
|
|
101
|
+
# Uses damerau-levenshtein to turn "one, two, three..." into "1, 2, 3..."
|
102
|
+
def convert_numbers_at_words_in value
|
103
|
+
|
104
|
+
NUMBER_WORDS.each_with_index do |word|
|
105
|
+
value.gsub!(word[0].to_s, word[1].to_s)
|
106
|
+
end
|
107
|
+
|
108
|
+
value
|
109
|
+
end
|
110
|
+
|
94
111
|
module HelperMethods
|
95
112
|
def validates_with_cold_shouldr(*attr_names)
|
96
113
|
validates_with ColdShoulderValidator, _merge_attributes(attr_names)
|