cold_shoulder 1.2.1 → 1.2.2
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 +11 -10
- 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: bbc5adc9bb11b031fedcdc40f0dffba8073a7edf
|
4
|
+
data.tar.gz: 222629fdd4c2940c5f4353b5f95682a1ef872e1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9073f23c561685051a8181aba1fb0f42ed066679010361d9a764c6cf48dec765365461062485caec2874a7a8e57e90e6ecae537c566ba2803962e84e9a7e569c
|
7
|
+
data.tar.gz: d1bd6ac470bcdcdf74f6bc3af9be308525c35eadc4aba167aac70a2b2c84e786292e5bb592d240313f3fd9c8704898aa125d7a66c7c14575bd2745313af5b53d
|
data/lib/validator.rb
CHANGED
@@ -35,10 +35,8 @@ module ActiveModel
|
|
35
35
|
|
36
36
|
def validate_each(record, attr_name, value)
|
37
37
|
|
38
|
-
value = convert_numbers_at_words_in(value) unless options[:ignore_number_words]
|
39
|
-
|
40
38
|
# Detect any contact methods in the value
|
41
|
-
detected = detect_contacts_in value
|
39
|
+
detected = detect_contacts_in value, options
|
42
40
|
|
43
41
|
# Add errors for detected methods, If there is a message, skip adding errors
|
44
42
|
errors = add_errors_to_record(record, attr_name, detected, {skip: options[:message]})
|
@@ -54,11 +52,15 @@ module ActiveModel
|
|
54
52
|
end
|
55
53
|
end
|
56
54
|
|
57
|
-
def detect_contacts_in value
|
55
|
+
def detect_contacts_in value, options
|
56
|
+
|
57
|
+
num_words_value = value
|
58
|
+
num_words_value = convert_numbers_at_words_in(value) unless options[:ignore_number_words]
|
59
|
+
|
58
60
|
# Remove spaces (the most basic way to avoid these detections)
|
59
|
-
globbed_value =
|
61
|
+
globbed_value = num_words_value.gsub ' ', ''
|
60
62
|
# Remove any characters not numbers or commas (commas are for $1,000 formatted numbers
|
61
|
-
bullshit_free_phone =
|
63
|
+
bullshit_free_phone = num_words_value.gsub /[^0-9,]|\n/i, ''
|
62
64
|
|
63
65
|
# Look for matches
|
64
66
|
detected = {
|
@@ -100,12 +102,11 @@ module ActiveModel
|
|
100
102
|
|
101
103
|
# Uses damerau-levenshtein to turn "one, two, three..." into "1, 2, 3..."
|
102
104
|
def convert_numbers_at_words_in value
|
103
|
-
|
105
|
+
converted = String.new(value)
|
104
106
|
NUMBER_WORDS.each_with_index do |word|
|
105
|
-
|
107
|
+
converted.gsub!(word[0].to_s, word[1].to_s)
|
106
108
|
end
|
107
|
-
|
108
|
-
value
|
109
|
+
converted
|
109
110
|
end
|
110
111
|
|
111
112
|
module HelperMethods
|