Class: Picky::Query::Tokens
- Defined in:
- lib/picky/query/tokens.rb,
lib/picky/query/or.rb
Overview
This class primarily handles switching through similar token constellations.
Direct Known Subclasses
Defined Under Namespace
Classes: Or
Constant Summary collapse
- @@or_splitting_pattern =
Creates a new Tokens object from a number of Strings.
/\|/- @@splitter =
Splitter.new @@or_splitting_pattern
Instance Attribute Summary collapse
-
#ignore_unassigned ⇒ Object
readonly
Returns the value of attribute ignore_unassigned.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Class Method Summary collapse
Instance Method Summary collapse
-
#+(other) ⇒ Object
Non-destructive addition.
- #==(other) ⇒ Object
-
#initialize(tokens, ignore_unassigned = false) ⇒ Tokens
constructor
Create a new Tokens object with the array of tokens passed in.
- #original ⇒ Object
-
#originals ⇒ Object
TODO.
-
#partialize_last ⇒ Object
Makes the last of the tokens partial.
-
#possible_combinations_in(categories) ⇒ Object
Generates an array in the form of [ [combination], # of token 1 [combination, combination, combination], # of token 2 [combination, combination] # of token 3 ].
-
#symbolize ⇒ Object
Symbolizes each of the tokens.
-
#texts ⇒ Object
TODO.
-
#to_s ⇒ Object
Just join the token original texts.
Constructor Details
#initialize(tokens, ignore_unassigned = false) ⇒ Tokens
Create a new Tokens object with the array of tokens passed in.
21 22 23 24 |
# File 'lib/picky/query/tokens.rb', line 21 def initialize tokens, ignore_unassigned = false @tokens = tokens @ignore_unassigned = ignore_unassigned end |
Instance Attribute Details
#ignore_unassigned ⇒ Object (readonly)
Returns the value of attribute ignore_unassigned.
11 12 13 |
# File 'lib/picky/query/tokens.rb', line 11 def ignore_unassigned @ignore_unassigned end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
11 12 13 |
# File 'lib/picky/query/tokens.rb', line 11 def tokens @tokens end |
Class Method Details
.processed(words, originals, ignore_unassigned = false) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/picky/query/tokens.rb', line 30 def self.processed words, originals, ignore_unassigned = false new(words.zip(originals).collect! do |word, original| w, *middle, rest = @@splitter.multi word if rest Or.new processed [w, *middle, rest], original.split(@@or_splitting_pattern) else Token.processed w, original end end, ignore_unassigned) end |
Instance Method Details
#+(other) ⇒ Object
Non-destructive addition.
99 100 101 |
# File 'lib/picky/query/tokens.rb', line 99 def + other self.class.new (@tokens + other.tokens), (self.ignore_unassigned || other.ignore_unassigned) end |
#==(other) ⇒ Object
93 94 95 |
# File 'lib/picky/query/tokens.rb', line 93 def == other self.tokens == other.tokens end |
#original ⇒ Object
82 83 84 |
# File 'lib/picky/query/tokens.rb', line 82 def original originals end |
#originals ⇒ Object
TODO
79 80 81 |
# File 'lib/picky/query/tokens.rb', line 79 def originals @tokens.map(&:original) end |
#partialize_last ⇒ Object
Makes the last of the tokens partial.
73 74 75 |
# File 'lib/picky/query/tokens.rb', line 73 def partialize_last @tokens.last.partial = true unless empty? end |
#possible_combinations_in(categories) ⇒ Object
Generates an array in the form of [
[combination], # of token 1
[combination, combination, combination], # of token 2
[combination, combination] # of token 3
]
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/picky/query/tokens.rb', line 48 def possible_combinations_in categories @tokens.inject([]) do |combinations, token| possible_combinations = token.possible_combinations categories # Note: Optimization for ignoring tokens that allocate to nothing and # can be ignored. # For example in a special search, where "florian" is not # mapped to any category. # if ignore_unassigned && possible_combinations.empty? combinations else combinations << possible_combinations end end end |
#symbolize ⇒ Object
Symbolizes each of the tokens.
67 68 69 |
# File 'lib/picky/query/tokens.rb', line 67 def symbolize @tokens.each &:symbolize! end |
#texts ⇒ Object
TODO
87 88 89 |
# File 'lib/picky/query/tokens.rb', line 87 def texts @tokens.map(&:text) end |
#to_s ⇒ Object
Just join the token original texts.
105 106 107 |
# File 'lib/picky/query/tokens.rb', line 105 def to_s originals.join ' ' end |