Module: StringUtilityBelt::RegexMe::Helper

Included in:
String
Defined in:
lib/string_utility_belt/regex_me_helper.rb

Constant Summary

A_VARIATIONS =
"(a|à|á|â|ã|ä)"
E_VARIATIONS =
"(e|è|é|ê|ë)"
I_VARIATIONS =
"(i|ì|í|î|ï)"
O_VARIATIONS =
"(o|ò|ó|ô|õ|ö)"
U_VARIATIONS =
"(u|ù|ú|û|ü)"
C_VARIATIONS =
"(c|ç)"
N_VARIATIONS =
"(n|ñ)"
LATIN_CHARS_VARIATIONS =
[A_VARIATIONS,
E_VARIATIONS,
I_VARIATIONS,
O_VARIATIONS,
U_VARIATIONS,
C_VARIATIONS,
N_VARIATIONS]
BORDER_TO =
{
  :ruby => {:left => '\b', :right => '\b' },
  :mysql => {:left => '[[:<:]]', :right => '[[:>:]]' }
}

Instance Method Summary (collapse)

Instance Method Details

- (Object) regex_builder(options)



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/string_utility_belt/regex_me_helper.rb', line 49

def regex_builder(options)
  if options[:any]
    replace_the_any_char_per_any_pattern
  end

  if options[:latin_chars_variations]
    replace_chars_includeds_in_latin_variation_list
  end

  if options[:border]
    insert_border(options[:border])
  end

  if options[:or]
    insert_OR
  end

  return self
end

- (Object) regex_latin_ci_list



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/string_utility_belt/regex_me_helper.rb', line 27

def regex_latin_ci_list
  memo = ""

  self.each_char do |char|
    changed = false

    for variations in LATIN_CHARS_VARIATIONS
      variations_pattern = Regexp.new(variations, Regexp::IGNORECASE)

      if char =~ variations_pattern
        changed = true
        memo.insert(-1, variations)
        break
      end
    end

    memo.insert(-1, char) unless changed
  end

  self.replace(memo)
end