Sha256: a3fddaf52ba4437c26efad5e22035820bdfce13e7d3f39895943b9b12c2a5892

Contents?: true

Size: 935 Bytes

Versions: 7

Compression:

Stored size: 935 Bytes

Contents

# encoding: utf-8

module Dusen
  class Parser

    WESTERNISH_WORD_CHARACTER =  '\\w\\-\\.;@_ÄÖÜäöüß' # this is wrong on so many levels
    TEXT_QUERY = /(?:"([^"]+)"|([#{WESTERNISH_WORD_CHARACTER}]+))/
    FIELD_QUERY = /(\w+)\:#{TEXT_QUERY}/

    def self.parse(query_string)
      query_string = query_string.dup # we are going to delete substrings in-place
      query = Query.new
      extract_field_query_tokens(query_string, query)
      extract_text_query_tokens(query_string, query)
      query
    end

    def self.extract_text_query_tokens(query_string, query)
      while query_string.sub!(TEXT_QUERY, '')
        value = "#{$1}#{$2}"
        query << Token.new(value)
      end
    end

    def self.extract_field_query_tokens(query_string, query)
      while query_string.sub!(FIELD_QUERY, '')
        field = $1
        value = "#{$2}#{$3}"
        query << Token.new(field, value)
      end
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dusen-0.4.10 lib/dusen/parser.rb
dusen-0.4.9 lib/dusen/parser.rb
dusen-0.4.8 lib/dusen/parser.rb
dusen-0.4.6 lib/dusen/parser.rb
dusen-0.4.5 lib/dusen/parser.rb
dusen-0.4.4 lib/dusen/parser.rb
dusen-0.4.3 lib/dusen/parser.rb