pms 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to pms version 0.0.2
5
+ This documentation refers to pms version 0.0.3
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -57,7 +57,7 @@ Rubyforge project:: <http://rubyforge.org/projects/pms>
57
57
 
58
58
  == LICENSE AND COPYRIGHT
59
59
 
60
- Copyright (C) 2008 Jens Wille
60
+ Copyright (C) 2008-2010 Jens Wille
61
61
 
62
62
  pms is free software: you can redistribute it and/or modify it under the
63
63
  terms of the GNU General Public License as published by the Free Software
data/lib/pms.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # #
4
4
  # pms - Poor Man's Search. #
5
5
  # #
6
- # Copyright (C) 2008 Jens Wille #
6
+ # Copyright (C) 2008-2010 Jens Wille #
7
7
  # #
8
8
  # Authors: #
9
9
  # Jens Wille <jens.wille@uni-koeln.de> #
@@ -40,6 +40,8 @@ class PMS
40
40
  token ? TokenProxy.new(self, token) : Proxy.new(self).and { |*a| yield(*a) }
41
41
  end
42
42
 
43
+ alias_method :/, :search
44
+
43
45
  def results
44
46
  @index.entries
45
47
  end
data/lib/pms/ext.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # #
4
4
  # A component of pms, Poor Man's Search. #
5
5
  # #
6
- # Copyright (C) 2008 Jens Wille #
6
+ # Copyright (C) 2008-2010 Jens Wille #
7
7
  # #
8
8
  # Authors: #
9
9
  # Jens Wille <jens.wille@uni-koeln.de> #
@@ -34,16 +34,18 @@ module PMS::Ext
34
34
  PMS.new(self).search(*args)
35
35
  end
36
36
 
37
+ alias_method :/, :search
38
+
37
39
  RECEIVERS.each { |klass|
38
40
  klass.send(:include, self)
39
41
  }
40
42
 
41
43
  end
42
44
 
43
- class File
45
+ class << File
44
46
 
45
- def self.search(file, *args)
46
- File.open(file.respond_to?(:path) ? file.path : file) { |f| f.search(*args) }
47
+ def search(file, *args)
48
+ open(file.respond_to?(:path) ? file.path : file) { |f| f.search(*args) }
47
49
  end
48
50
 
49
51
  end
data/lib/pms/index.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # #
4
4
  # A component of pms, Poor Man's Search. #
5
5
  # #
6
- # Copyright (C) 2008 Jens Wille #
6
+ # Copyright (C) 2008-2010 Jens Wille #
7
7
  # #
8
8
  # Authors: #
9
9
  # Jens Wille <jens.wille@uni-koeln.de> #
@@ -68,7 +68,7 @@ class PMS
68
68
 
69
69
  def documents(doc_nums = default = Object.new)
70
70
  @documents ||= get_documents
71
- default ? @documents : doc_nums.map { |doc_num| @documents[doc_num] }
71
+ default ? @documents : @documents.values_at(*doc_nums)
72
72
  end
73
73
 
74
74
  alias_method :matches, :documents
data/lib/pms/proxy.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # #
4
4
  # A component of pms, Poor Man's Search. #
5
5
  # #
6
- # Copyright (C) 2008 Jens Wille #
6
+ # Copyright (C) 2008-2010 Jens Wille #
7
7
  # #
8
8
  # Authors: #
9
9
  # Jens Wille <jens.wille@uni-koeln.de> #
@@ -41,16 +41,22 @@ class PMS
41
41
  apply_operator_with_block('and') { |*a| yield(*a) }
42
42
  end
43
43
 
44
+ alias_method :&, :and
45
+
44
46
  def or(token = nil)
45
47
  token ? apply_operator_with_token('or', token) :
46
48
  apply_operator_with_block('or') { |*a| yield(*a) }
47
49
  end
48
50
 
51
+ alias_method :|, :or
52
+
49
53
  def not(token = nil)
50
54
  token ? apply_operator_with_token('not', token) :
51
55
  apply_operator_with_block('not') { |*a| yield(*a) }
52
56
  end
53
57
 
58
+ alias_method :-, :not
59
+
54
60
  def matches
55
61
  index.matches(results)
56
62
  end
@@ -132,10 +138,15 @@ class PMS
132
138
  apply_operator('and', doc_nums)
133
139
  end
134
140
 
141
+ alias_method :%, :near
142
+
135
143
  def adjacent(token, distance = 1)
136
144
  near(token, distance, true)
137
145
  end
138
146
 
147
+ alias_method :adj, :adjacent
148
+ alias_method :^, :adjacent
149
+
139
150
  end
140
151
 
141
152
  end
data/lib/pms/version.rb CHANGED
@@ -4,7 +4,7 @@ class PMS
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 0
7
- TINY = 2
7
+ TINY = 3
8
8
 
9
9
  class << self
10
10
 
data/spec/pms/ext_spec.rb CHANGED
@@ -28,6 +28,22 @@ shared_examples_for 'any Searchable' do
28
28
 
29
29
  end
30
30
 
31
+ shared_examples_for 'most Searchables' do
32
+
33
+ it 'should allow boolean combination with & (AND)' do
34
+ (@searchable/'fox' & 'goose').results.sort.should == [3, 6]
35
+ end
36
+
37
+ it 'should allow boolean combination with | (OR)' do
38
+ (@searchable/'fox' | 'goose').results.sort.should == [0, 2, 3, 4, 6]
39
+ end
40
+
41
+ it 'should allow boolean combination with - (NOT)' do
42
+ (@searchable/'fox' - 'goose').results.sort.should == [0, 4]
43
+ end
44
+
45
+ end
46
+
31
47
  describe String, ' when extended by pms' do
32
48
 
33
49
  before :each do
@@ -35,6 +51,7 @@ describe String, ' when extended by pms' do
35
51
  end
36
52
 
37
53
  it_should_behave_like 'any Searchable'
54
+ it_should_behave_like 'most Searchables'
38
55
 
39
56
  end
40
57
 
@@ -45,6 +62,7 @@ describe IO, ' when extended by pms' do
45
62
  end
46
63
 
47
64
  it_should_behave_like 'any Searchable'
65
+ it_should_behave_like 'most Searchables'
48
66
 
49
67
  end
50
68
 
@@ -55,6 +73,7 @@ describe Array, ' when extended by pms' do
55
73
  end
56
74
 
57
75
  it_should_behave_like 'any Searchable'
76
+ it_should_behave_like 'most Searchables'
58
77
 
59
78
  end
60
79
 
data/spec/pms_spec.rb CHANGED
@@ -20,14 +20,26 @@ describe PMS do
20
20
  @pms.search('fox').and('goose').results.sort.should == [3, 6]
21
21
  end
22
22
 
23
+ it 'should support boolean operator & (AND)' do
24
+ (@pms/'fox' & 'goose').results.sort.should == [3, 6]
25
+ end
26
+
23
27
  it 'should support boolean operator OR' do
24
28
  @pms.search('fox').or('goose').results.sort.should == [0, 2, 3, 4, 6]
25
29
  end
26
30
 
31
+ it 'should support boolean operator | (OR)' do
32
+ (@pms/'fox' | 'goose').results.sort.should == [0, 2, 3, 4, 6]
33
+ end
34
+
27
35
  it 'should support boolean operator NOT' do
28
36
  @pms.search('fox').not('goose').results.sort.should == [0, 4]
29
37
  end
30
38
 
39
+ it 'should support boolean operator - (NOT)' do
40
+ (@pms/'fox' - 'goose').results.sort.should == [0, 4]
41
+ end
42
+
31
43
  it 'should allow chaining of operators' do
32
44
  @pms.search('fox').and('goose').not('knife').results.sort.should == [3]
33
45
  end
@@ -58,10 +70,22 @@ describe PMS do
58
70
  @pms.search('fox').near('goose', 10).results.sort.should == [3, 6]
59
71
  end
60
72
 
73
+ it 'should support proximity operator % (NEAR)' do
74
+ (@pms/'night' % 'chilly').results.sort.should == [0]
75
+ end
76
+
61
77
  it 'should support proximity operator ADJACENT' do
62
78
  @pms.search('fox').adjacent('goose', 10).results.sort.should == [6]
63
79
  end
64
80
 
81
+ it 'should support proximity operator ADJ (ADJACENT)' do
82
+ @pms.search('fox').adj('goose', 10).results.sort.should == [6]
83
+ end
84
+
85
+ it 'should support proximity operator ^ (ADJACENT)' do
86
+ (@pms/'chilly' ^ 'night').results.sort.should == [0]
87
+ end
88
+
65
89
  it 'should search case-insensitively' do
66
90
  @pms.search('said').results.sort.should == [1, 4]
67
91
  @pms.search('Said').results.sort.should == [1, 4]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Wille
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-09 00:00:00 +01:00
12
+ date: 2010-02-18 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -25,32 +25,34 @@ extra_rdoc_files:
25
25
  - README
26
26
  files:
27
27
  - lib/pms.rb
28
+ - lib/pms/index.rb
28
29
  - lib/pms/proxy.rb
29
30
  - lib/pms/ext.rb
30
31
  - lib/pms/version.rb
31
- - lib/pms/index.rb
32
+ - README
33
+ - ChangeLog
32
34
  - Rakefile
33
35
  - COPYING
34
- - ChangeLog
35
- - README
36
- - spec/spec_helper.rb
37
- - spec/pms/proxy_spec.rb
38
36
  - spec/pms/index_spec.rb
39
37
  - spec/pms/ext_spec.rb
38
+ - spec/pms/proxy_spec.rb
39
+ - spec/spec_helper.rb
40
40
  - spec/pms_spec.rb
41
41
  - test_data/fox.txt
42
42
  has_rdoc: true
43
43
  homepage: http://pms.rubyforge.org/
44
+ licenses: []
45
+
44
46
  post_install_message:
45
47
  rdoc_options:
46
- - --line-numbers
47
- - --inline-source
48
+ - --charset
49
+ - UTF-8
48
50
  - --title
49
51
  - pms Application documentation
50
52
  - --main
51
53
  - README
52
- - --charset
53
- - UTF-8
54
+ - --line-numbers
55
+ - --inline-source
54
56
  - --all
55
57
  require_paths:
56
58
  - lib
@@ -69,9 +71,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
71
  requirements: []
70
72
 
71
73
  rubyforge_project: pms
72
- rubygems_version: 1.3.1
74
+ rubygems_version: 1.3.5
73
75
  signing_key:
74
- specification_version: 2
76
+ specification_version: 3
75
77
  summary: Poor Man's Search
76
78
  test_files: []
77
79