Class: ElasticsearchQueryParser::Sentence

Inherits:
Object
  • Object
show all
Defined in:
lib/elasticsearch_query_parser/sentence.rb

Overview

Transform user query to ‘Left to Right` expression for parser usage

Constant Summary collapse

WORD_SPLITTER_REGEX =

Split by whitespace, but not split words in quotes

/(?:'(?:\\.|[^'])*'|[^' ])+/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(sentence) ⇒ Sentence

Initialize with user input



11
12
13
# File 'lib/elasticsearch_query_parser/sentence.rb', line 11

def initialize(sentence)
  @sentence = sentence
end

Instance Method Details

#to_sObject

Return valid for parser usage user input Example:

>> ElasticsearchQueryParser.new("(London AND Madrid) OR Paris").to_s
=> "Paris OR ( Madrid AND London )"


19
20
21
# File 'lib/elasticsearch_query_parser/sentence.rb', line 19

def to_s
  left_to_right? ? sentence : revert_left_to_right
end