acts_as_tokenizable 0.3.2 → 0.3.3

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.
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{acts_as_tokenizable}
8
- s.version = "0.3.2"
8
+ s.version = "0.3.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Enrique Garcia Cota", "Francisco de Juan"]
@@ -32,8 +32,13 @@ module ActsAsTokenizable
32
32
  search_strings = []
33
33
  search_values = []
34
34
  prepare_search_token(search_token).words.each do |w|
35
- search_strings.push("#{table_name}.#{token_field_name} LIKE ?")
36
- search_values.push("%#{w}%")
35
+ if w[0,1] == '-'
36
+ search_strings.push("#{table_name}.#{token_field_name} NOT LIKE ?")
37
+ search_values.push("%#{w[1,w.length]}%")
38
+ else
39
+ search_strings.push("#{table_name}.#{token_field_name} LIKE ?")
40
+ search_values.push("%#{w}%")
41
+ end
37
42
  end
38
43
  {:conditions => [search_strings.join(' AND '), *search_values]}
39
44
  }
@@ -15,7 +15,7 @@ String.class_eval do
15
15
 
16
16
  #returns an array of strings containing the words on this string. removes spaces, strange chars, etc
17
17
  def words
18
- gsub(/\W/, ' ').split
18
+ gsub(/[^\w|-]/, ' ').split
19
19
  end
20
20
 
21
21
  #removes certain words from a string.
@@ -49,7 +49,7 @@ String.class_eval do
49
49
 
50
50
  #convert into something that can be used as an indexation key
51
51
  def to_token(max_length=255)
52
- string = self.normalize.strip.downcase.gsub(/\W/, '') #remove all non-alphanumeric
52
+ string = self.normalize.strip.downcase.gsub(/[^\w|-]/, '') #remove all non-alphanumeric but hyphen (-)
53
53
  string = string.squeeze unless string.numeric? #remove duplicates, except on pure numbers
54
54
  return string[0..(max_length-1)]
55
55
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 2
9
- version: 0.3.2
8
+ - 3
9
+ version: 0.3.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Enrique Garcia Cota