string_utility_belt 0.1.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,37 @@
1
1
 
2
2
  class String
3
+
4
+ LATIN_CHARS_VARIATION = ["[aàáâãä]", "[eèéêë]", "[iìíîï]", "[oòóôõö]", "[uùúûü]", "[cçÇ]", "[ñÑ]"]
5
+
6
+ def regex_latin_ci_list
7
+
8
+ memo = ""
9
+ self.each_char do |char|
10
+
11
+ variation_found = false
12
+
13
+ for char_variation in LATIN_CHARS_VARIATION
14
+
15
+ match = eval("/#{char_variation}/")
16
+
17
+ if (char =~ match)
18
+ memo.insert(-1, char_variation)
19
+ variation_found = true
20
+ break
21
+ end
22
+ end
23
+
24
+ memo.insert(-1, char) unless variation_found
25
+ end
26
+
27
+ self.replace(memo)
28
+ end
3
29
 
4
30
  def regex_builder options={}
5
31
  self.gsub!(/\*/,'.*') if options[:any]
6
32
  border_me(options[:border][:to],
7
33
  options[:border][:direction]) if options[:border]
34
+ regex_latin_ci_list if options[:latin_chars_variation]
8
35
  insert_OR_in_right unless options[:delete_or]
9
36
  self
10
37
  end
@@ -10,10 +10,11 @@ module RegexMe
10
10
  private
11
11
  def options_handler options
12
12
  {
13
- :exact_word => options[:exact_word],
14
- :case_insensitive => (options[:case_insensitive] ? :i : nil ),
15
- :m => (options[:m] ? :m : nil ),
16
- :exact_phrase => options[:exact_phrase]
13
+ :exact_word => options[:exact_word],
14
+ :case_insensitive => (options[:case_insensitive] ? :i : nil ),
15
+ :latin_chars_variation => options[:latin_chars_variation],
16
+ :m => (options[:m] ? :m : nil ),
17
+ :exact_phrase => options[:exact_phrase]
17
18
  }
18
19
  end
19
20
 
@@ -37,7 +38,7 @@ module RegexMe
37
38
 
38
39
  private
39
40
  def execute_builder string, opt_handled, border_to
40
- result_builder = builder(string, opt_handled[:exact_word], border_to, opt_handled[:exact_phrase])
41
+ result_builder = builder(string, opt_handled[:exact_word], border_to, opt_handled[:latin_chars_variation], opt_handled[:exact_phrase])
41
42
 
42
43
  case border_to
43
44
  when :ruby
@@ -48,23 +49,26 @@ module RegexMe
48
49
 
49
50
  end
50
51
 
51
- def builder string, exact_word, border_to, exact_phrase
52
+ def builder string, exact_word, border_to, latin_chars_variation, exact_phrase
52
53
 
53
54
  if exact_phrase
54
- regexp = string.gsub(/\s+/, " ").gsub(/\s/, '[^0-9a-zA-Z\_]+').regex_builder(:delete_or => true, :border => {:to => border_to, :direction => :both})
55
+ regexp = string.gsub(/\s+/, " ").gsub(/\s/, '[^0-9a-zA-Z\_]+').regex_builder(:latin_chars_variation => latin_chars_variation,
56
+ :delete_or => true,
57
+ :border => {:to => border_to,
58
+ :direction => :both})
55
59
  else
56
60
  regexp = '('
57
61
 
58
62
  for word in string.strip.split
59
63
  case word
60
64
  when/^\*/
61
- regexp << word.regex_builder(:any => true, :border => {:to => border_to, :direction => :right})
65
+ regexp << word.regex_builder(:any => true, :border => {:to => border_to, :direction => :right}, :latin_chars_variation => latin_chars_variation)
62
66
  when /\*$/
63
- regexp << word.regex_builder(:any => true, :border => {:to => border_to, :direction => :left})
67
+ regexp << word.regex_builder(:any => true, :border => {:to => border_to, :direction => :left}, :latin_chars_variation => latin_chars_variation)
64
68
  when /^.*\*.*$/
65
- regexp << word.regex_builder(:any => true, :border => {:to => border_to, :direction => :both})
69
+ regexp << word.regex_builder(:any => true, :border => {:to => border_to, :direction => :both}, :latin_chars_variation => latin_chars_variation)
66
70
  else
67
- regexp << (exact_word ? word.regex_builder(:border => {:to => border_to, :direction => :both}) : word.regex_builder)
71
+ regexp << (exact_word ? word.regex_builder(:border => {:to => border_to, :direction => :both}, :latin_chars_variation => latin_chars_variation) : word.regex_builder(:latin_chars_variation => latin_chars_variation))
68
72
  end
69
73
  end
70
74
 
@@ -1,7 +1,7 @@
1
1
  module StringUtilityBelt
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 1
4
+ MINOR = 2
5
5
  PATCH = 1
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
@@ -2,7 +2,7 @@ $LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "string_utility_belt"
5
- s.version = "0.1.1"
5
+ s.version = "0.2.1"
6
6
  s.description = "Useful methods for strings!"
7
7
  s.summary = "Useful methods for strings!"
8
8
  s.author = "Rodrigo Serradura"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string_utility_belt
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 2
8
9
  - 1
9
- - 1
10
- version: 0.1.1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rodrigo Serradura