Class: TextQuery

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

Instance Method Summary collapse

Constructor Details

#initialize(query = '', options = {}) ⇒ TextQuery

Returns a new instance of TextQuery.



66
67
68
69
70
71
72
# File 'lib/textquery/textquery.rb', line 66

def initialize(query = '', options = {})
  @parser = TextQueryGrammarParser.new
  @query  = nil

  update_options(options)
  parse(query) if not query.empty?
end

Instance Method Details

#accept(options = {}, &block) ⇒ Object



94
95
96
97
98
99
100
101
102
# File 'lib/textquery/textquery.rb', line 94

def accept(options = {}, &block)
  update_options(options) if not options.empty?

  if @query
    @query.accept(&block)
  else
    raise TextQueryError, 'no query specified'
  end
end

#eval(input, options = {}) ⇒ Object Also known as: match?



83
84
85
86
87
88
89
90
91
# File 'lib/textquery/textquery.rb', line 83

def eval(input, options = {})
  update_options(options) if not options.empty?

  if @query
    @query.eval(input, @options)
  else
    raise TextQueryError, 'no query specified'
  end
end

#parse(query) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/textquery/textquery.rb', line 74

def parse(query)
  query = query.mb_chars if RUBY_VERSION < '1.9'
  @query = @parser.parse(query)
  if not @query
    raise TextQueryError, "Could not parse query string '#{query}': #{@parser.terminal_failures.inspect}"
  end
  self
end

#terminal_failuresObject



104
105
106
# File 'lib/textquery/textquery.rb', line 104

def terminal_failures
  @parser.terminal_failures
end