Class: Picky::Try

Inherits:
Object show all
Defined in:
lib/tasks/try.rb

Overview

Try is used by

rake try[text,index,category]

to test how the text would be indexed and processed during a search.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, index = nil, category = nil) ⇒ Try

Returns a new instance of Try.



11
12
13
14
15
16
# File 'lib/tasks/try.rb', line 11

def initialize text, index = nil, category = nil
  @text = text
  @specific = Picky::Indexes
  @specific = @specific[index.intern]    if index
  @specific = @specific[category.intern] if category
end

Instance Attribute Details

#specificObject (readonly)

Returns the value of attribute specific.



9
10
11
# File 'lib/tasks/try.rb', line 9

def specific
  @specific
end

#textObject (readonly)

Returns the value of attribute text.



9
10
11
# File 'lib/tasks/try.rb', line 9

def text
  @text
end

Instance Method Details

#outputObject



26
27
28
29
30
31
32
33
# File 'lib/tasks/try.rb', line 26

def output
  "\\\"\#{text}\\\" is saved in the \#{specific.identifier} index as \#{saved}\n\\\"\#{text}\\\" as a search will be tokenized as \#{searched}\n\n(category qualifiers, e.g. title: are removed if they do not exist as a qualifier, so 'toitle:bla' -> 'bla')\n  OUTPUT\nend\n"

#savedObject



18
19
20
# File 'lib/tasks/try.rb', line 18

def saved
  specific.tokenizer.tokenize(text.dup).first
end

#searchedObject



22
23
24
# File 'lib/tasks/try.rb', line 22

def searched
  Picky::Tokenizer.searching.tokenize(text.dup).first
end

#to_stdoutObject



35
36
37
# File 'lib/tasks/try.rb', line 35

def to_stdout
  puts output
end