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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/validator.rb +11 -10
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e39b4d0880880293156ef14b3a250f1d15f4f07a
4
- data.tar.gz: 3200be955fde4a5a3e25e7a5c6ffd8b6c994bec5
3
+ metadata.gz: bbc5adc9bb11b031fedcdc40f0dffba8073a7edf
4
+ data.tar.gz: 222629fdd4c2940c5f4353b5f95682a1ef872e1f
5
5
  SHA512:
6
- metadata.gz: 876e89ec45c6f4336b90c83b16c2548b7232b72e3eec40cf1a764fa88ab91f206113809dcae743e0de86b34eeb359b2e487f24c73a25569333a7cb8d6b4fd3fd
7
- data.tar.gz: 057dc821f926bab1603de78919964ab58852b510950ad10e11ba37e85d77870fe847a4b107be586a395fc74316f8da23b866bbbebbe7f12f814ab16653911625
6
+ metadata.gz: 9073f23c561685051a8181aba1fb0f42ed066679010361d9a764c6cf48dec765365461062485caec2874a7a8e57e90e6ecae537c566ba2803962e84e9a7e569c
7
+ data.tar.gz: d1bd6ac470bcdcdf74f6bc3af9be308525c35eadc4aba167aac70a2b2c84e786292e5bb592d240313f3fd9c8704898aa125d7a66c7c14575bd2745313af5b53d
@@ -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 = value.gsub ' ', ''
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 = value.gsub /[^0-9,]|\n/i, ''
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
- value.gsub!(word[0].to_s, word[1].to_s)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cold_shoulder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Hoffman