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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/validator.rb +18 -1
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b5c1034d690bd1bf262b7d491ff281e44b9d714
4
- data.tar.gz: 655709b9dc3d1678480f920784312fffac10a1ac
3
+ metadata.gz: e39b4d0880880293156ef14b3a250f1d15f4f07a
4
+ data.tar.gz: 3200be955fde4a5a3e25e7a5c6ffd8b6c994bec5
5
5
  SHA512:
6
- metadata.gz: f5648f2978c4ac0a1eae514fc2d14d409a9897b0b1ba3b21869ec76bdc32000a8ad3004b7aa5523e8b03ef5609a92470b3c9af7f4aad97ce9790e8116e67a46d
7
- data.tar.gz: 8aed809493caa45f827128278e383af6435201f75aaf202b706fc98d6da38824ee41fbce6160d11897c4ccfbd3874556139df23eba7d3e049fb3403a1f208209
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)
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.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Hoffman