textquery 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ pkg
2
+ textquery.gemspec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -72,8 +72,7 @@ class TextQuery
72
72
  private
73
73
 
74
74
  def update_options(options)
75
- @options = {:delim => ' '}.merge options
76
- @options[:delim] = Regexp.escape @options[:delim]
75
+ @options = {:delim => ' '}.merge(options)
76
+ @options[:delim] = "(#{[@options[:delim]].flatten.map { |opt| Regexp.escape(opt) }.join("|")})"
77
77
  end
78
-
79
78
  end
@@ -49,7 +49,11 @@ grammar TextQueryGrammar
49
49
  end
50
50
 
51
51
  rule words
52
- [^\']+ <WordMatch>
52
+ [^'"]+ <WordMatch>
53
+ end
54
+
55
+ rule quote
56
+ ['"]
53
57
  end
54
58
 
55
59
  rule value
@@ -65,7 +69,7 @@ grammar TextQueryGrammar
65
69
  end
66
70
  }
67
71
  /
68
- "'" space words space "'" {
72
+ quote space words space quote {
69
73
  def eval(text, opt)
70
74
  words.eval(text, opt)
71
75
  end
@@ -73,5 +77,4 @@ grammar TextQueryGrammar
73
77
  /
74
78
  word
75
79
  end
76
-
77
80
  end
@@ -132,6 +132,7 @@ describe TextQuery do
132
132
 
133
133
  # shakespeare got nothin' on ruby...
134
134
  parse("'to be' OR NOT 'to be'").eval("to be").should be_true
135
+ parse('"to be" OR NOT "to be"').eval("to be").should be_true
135
136
  end
136
137
 
137
138
  it "should treat spaces as implicit ANDs" do
@@ -199,4 +200,29 @@ describe TextQuery do
199
200
  TextQuery.new("a AND CD", :ignorecase => false).match?("A b cD").should be_false
200
201
  end
201
202
 
203
+ context 'delimiters' do
204
+ it 'should default to space delimiter' do
205
+ TextQuery.new("a").match?("a b").should be_true
206
+ TextQuery.new("a").match?("a*b").should be_false
207
+ end
208
+
209
+ it 'should accept a string delimiter' do
210
+ TextQuery.new("a", :delim => "*").match?("a*b").should be_true
211
+ TextQuery.new("a", :delim => "*").match?("a b").should be_false
212
+ end
213
+
214
+ it 'should accept an array of delimiters' do
215
+ TextQuery.new("a", :delim => ["*"]).match?("a*b").should be_true
216
+ end
217
+
218
+ it 'should OR delimiters together when provided as an array' do
219
+ TextQuery.new("a", :delim => ["*", "|"]).match?("a|b").should be_true
220
+ TextQuery.new("a", :delim => ["*", "|"]).match?("a*b").should be_true
221
+ TextQuery.new("a", :delim => ["*", "|"]).match?("a b").should be_false
222
+ end
223
+
224
+ it 'should not match just the delimiter' do
225
+ TextQuery.new("a*b", :delim => ["*", "<"]).match?("over<under").should be_false
226
+ end
227
+ end
202
228
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: textquery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Grigorik
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-30 00:00:00 -05:00
12
+ date: 2010-01-05 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -31,6 +31,7 @@ extensions: []
31
31
  extra_rdoc_files:
32
32
  - README.rdoc
33
33
  files:
34
+ - .gitignore
34
35
  - README.rdoc
35
36
  - Rakefile
36
37
  - VERSION