Class: Dusen::Query
Instance Attribute Summary collapse
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Instance Method Summary collapse
- #<<(token) ⇒ Object
- #[](index) ⇒ Object
- #condensed ⇒ Object
- #each(&block) ⇒ Object
- #exclude ⇒ Object
- #include ⇒ Object
-
#initialize(initial_tokens = []) ⇒ Query
constructor
A new instance of Query.
-
#to_s ⇒ Object
def +(tokens) tokens.each do |token| self << token end end.
Constructor Details
#initialize(initial_tokens = []) ⇒ Query
Returns a new instance of Query.
10 11 12 |
# File 'lib/dusen/query.rb', line 10 def initialize(initial_tokens = []) @tokens = initial_tokens end |
Instance Attribute Details
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
8 9 10 |
# File 'lib/dusen/query.rb', line 8 def tokens @tokens end |
Instance Method Details
#<<(token) ⇒ Object
14 15 16 |
# File 'lib/dusen/query.rb', line 14 def <<(token) tokens << token end |
#[](index) ⇒ Object
18 19 20 |
# File 'lib/dusen/query.rb', line 18 def [](index) tokens[index] end |
#condensed ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/dusen/query.rb', line 36 def condensed include_texts = include.select(&:text?).collect(&:value) exclude_texts = exclude.select(&:text?).collect(&:value) field_tokens = tokens.reject(&:text?) condensed_tokens = field_tokens if include_texts.present? = { :field => 'text', :value => include_texts, :exclude => false } condensed_tokens << Token.new() end if exclude_texts.present? = { :field => 'text', :value => exclude_texts, :exclude => true } condensed_tokens << Token.new() end self.class.new(condensed_tokens) end |
#each(&block) ⇒ Object
32 33 34 |
# File 'lib/dusen/query.rb', line 32 def each(&block) tokens.each(&block) end |
#exclude ⇒ Object
57 58 59 |
# File 'lib/dusen/query.rb', line 57 def exclude self.class.new tokens.select(&:exclude?) end |
#include ⇒ Object
53 54 55 |
# File 'lib/dusen/query.rb', line 53 def include self.class.new tokens.reject(&:exclude?) end |
#to_s ⇒ Object
def +(tokens)
tokens.each do |token|
self << token
end
end
28 29 30 |
# File 'lib/dusen/query.rb', line 28 def to_s collect(&:to_s).join(" + ") end |