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.



57
58
59
60
61
62
63
# File 'lib/textquery/textquery.rb', line 57

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

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

Instance Method Details

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



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

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



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

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



85
86
87
# File 'lib/textquery/textquery.rb', line 85

def terminal_failures
  @parser.terminal_failures
end