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
-
#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 |
# File 'lib/dusen/query.rb', line 36 def condensed texts = tokens.select(&:text?).collect(&:value) field_tokens = tokens.reject(&:text?) condensed_tokens = field_tokens condensed_tokens << Token.new(texts) if texts.present? 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 |
#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 |