sewell 0.1.0 → 0.1.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.
- data/README.md +2 -2
- data/lib/sewell.rb +11 -2
- data/lib/sewell/version.rb +1 -1
- data/spec/sewell/sewell_spec.rb +2 -2
- metadata +1 -1
data/README.md
CHANGED
@@ -25,8 +25,8 @@ Or install it yourself as:
|
|
25
25
|
Sewell.generate({sena: 'airi OR huro', nuko: 'trape'}, 'AND') #=> ( sena:@airi OR sena:@huro ) + ( nuko:@trape )
|
26
26
|
Sewell.generate({sena: 'airi OR huro', nuko: 'trape'}, 'OR') #=> ( sena:@airi OR sena:@huro ) OR ( nuko:@trape )
|
27
27
|
|
28
|
-
Sewell.generate({mashiro: '-inui airi'}) #=> ( mashiro
|
29
|
-
Sewell.generate('-inui airi', ['mashiro']) #=> ( mashiro
|
28
|
+
Sewell.generate({mashiro: '-inui airi'}) #=> ( mashiro:@airi - mashiro:@inui )
|
29
|
+
Sewell.generate('-inui airi', ['mashiro']) #=> ( mashiro:@airi - mashiro:@inui )
|
30
30
|
```
|
31
31
|
|
32
32
|
## Contributing
|
data/lib/sewell.rb
CHANGED
@@ -30,7 +30,7 @@ module Sewell
|
|
30
30
|
else
|
31
31
|
if x.split('').first == '-'
|
32
32
|
x.sub!(/^-/, '')
|
33
|
-
"#{k}
|
33
|
+
" - #{k}:@#{sanitize x, /#{k}\:/}"
|
34
34
|
else
|
35
35
|
"#{k}:@#{sanitize x, /#{k}\:/}"
|
36
36
|
end
|
@@ -55,7 +55,7 @@ module Sewell
|
|
55
55
|
else
|
56
56
|
if x.split('').first == '-'
|
57
57
|
x.sub!(/^-/, '')
|
58
|
-
q << '( ' + tables.map{|t| "#{t}
|
58
|
+
q << ' - ( ' + tables.map{|t| "#{t}:@#{sanitize(x)}"}.join(' OR ') + ' )'
|
59
59
|
else
|
60
60
|
q << '( ' + tables.map{|t| "#{t}:@#{sanitize(x)}"}.join(' OR ') + ' )'
|
61
61
|
end
|
@@ -70,6 +70,13 @@ module Sewell
|
|
70
70
|
else
|
71
71
|
sep = '+'
|
72
72
|
end
|
73
|
+
|
74
|
+
raise if q.map{|x| x =~ /^\ -\ /}.select{|x| x}.count == q.count
|
75
|
+
|
76
|
+
while q.first =~ /^\ -\ /
|
77
|
+
q.push q.shift
|
78
|
+
end
|
79
|
+
|
73
80
|
query = ''
|
74
81
|
q.each_with_index{|x,i|
|
75
82
|
next if x == 'OR' or x == 'AND'
|
@@ -77,6 +84,8 @@ module Sewell
|
|
77
84
|
query += "#{x} OR "
|
78
85
|
elsif q[i+1] == 'AND'
|
79
86
|
query += "#{x} + "
|
87
|
+
elsif q[i+1] and q[i+1] =~ /^\ -\ /
|
88
|
+
query += x
|
80
89
|
elsif q[i+1] != nil
|
81
90
|
query += "#{x} #{sep} "
|
82
91
|
else
|
data/lib/sewell/version.rb
CHANGED
data/spec/sewell/sewell_spec.rb
CHANGED
@@ -8,11 +8,11 @@ describe Sewell do
|
|
8
8
|
|
9
9
|
it 'can generate from string' do
|
10
10
|
Sewell.generate('sena:airi OR mashiro AND nuko:buta', %w{sena uryu nuko}).should == '( sena:@airi ) OR ( sena:@mashiro OR uryu:@mashiro OR nuko:@mashiro ) + ( nuko:@buta )'
|
11
|
-
Sewell.generate('-inui airi', ['mashiro']).should == '( mashiro
|
11
|
+
Sewell.generate('-inui airi', ['mashiro']).should == '( mashiro:@airi ) - ( mashiro:@inui )'
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'can generate from hash' do
|
15
15
|
Sewell.generate({sena: 'airi OR huro', nuko: 'trape'}, 'AND').should == '( sena:@airi OR sena:@huro ) + ( nuko:@trape )'
|
16
|
-
Sewell.generate({mashiro: '-inui airi'}, 'AND').should == '( mashiro
|
16
|
+
Sewell.generate({mashiro: '-inui airi'}, 'AND').should == '( mashiro:@airi - mashiro:@inui )'
|
17
17
|
end
|
18
18
|
end
|