sewell 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
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:!inui + mashiro:@airi )
29
- Sewell.generate('-inui airi', ['mashiro']) #=> ( mashiro:!inui + mashiro:@airi )
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}:!#{sanitize x, /#{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}:!#{sanitize(x)}"}.join(' AND ') + ' )'
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
@@ -1,3 +1,3 @@
1
1
  module Sewell
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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:!inui ) + ( mashiro:@airi )'
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:!inui + mashiro:@airi )'
16
+ Sewell.generate({mashiro: '-inui airi'}, 'AND').should == '( mashiro:@airi - mashiro:@inui )'
17
17
  end
18
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sewell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: