Sha256: b0ae2843ad138603dd1cda2f54c02aa32a9af88bbd8adc15c4659327501fc525

Contents?: true

Size: 750 Bytes

Versions: 11

Compression:

Stored size: 750 Bytes

Contents

# encoding: utf-8

module Dusen
  class Query

    include Enumerable

    attr_reader :tokens

    def initialize(initial_tokens = [])
      @tokens = initial_tokens
    end

    def <<(token)
      tokens << token
    end

    def [](index)
      tokens[index]
    end

    #def +(tokens)
    #  tokens.each do |token|
    #    self << token
    #  end
    #end

    def to_s
      collect(&:to_s).join(" + ")
    end

    def each(&block)
      tokens.each(&block)
    end

    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

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
dusen-0.4.10 lib/dusen/query.rb
dusen-0.4.9 lib/dusen/query.rb
dusen-0.4.8 lib/dusen/query.rb
dusen-0.4.6 lib/dusen/query.rb
dusen-0.4.5 lib/dusen/query.rb
dusen-0.4.4 lib/dusen/query.rb
dusen-0.4.3 lib/dusen/query.rb
dusen-0.4.2 lib/dusen/query.rb
dusen-0.4.1 lib/dusen/query.rb
dusen-0.4.0 lib/dusen/query.rb
dusen-0.3.0 lib/dusen/query.rb