-
Notifications
You must be signed in to change notification settings - Fork 49
/
customized.rb
37 lines (29 loc) · 917 Bytes
/
customized.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require File.expand_path '../../../server/lib/picky', __FILE__
Person = Struct.new :id, :first, :last
# Our special partializer only allows partials
# of even length.
#
class Partializer
def each_partial text
temp = text.dup
temp.length.times do
yield temp if temp.size.even?
temp.chop!
end
end
end
data = Picky::Index.new :people do
category :first
category :last, partial: Partializer.new # <= Passed in here.
end
data.replace Person.new(1, 'Donald', 'Knuth')
data.replace Person.new(2, 'Niklaus', 'Wirth')
data.replace Person.new(3, 'Donald', 'North')
data.replace Person.new(4, 'Peter', 'Niklaus')
people = Picky::Search.new data
# Finds only even partials.
#
fail __FILE__ unless people.search('n').ids == []
fail __FILE__ unless people.search('no').ids == [3]
fail __FILE__ unless people.search('nor').ids == []
fail __FILE__ unless people.search('nort').ids == [3]