Class: TextQuery
- Inherits:
-
Object
- Object
- TextQuery
- Defined in:
- lib/textquery/textquery.rb
Instance Method Summary collapse
- #eval(input, options = {}) ⇒ Object (also: #match?)
-
#initialize(query = '', options = {}) ⇒ TextQuery
constructor
A new instance of TextQuery.
- #parse(query) ⇒ Object
- #terminal_failures ⇒ Object
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 = '', = {}) @parser = TextQueryGrammarParser.new @query = nil () 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, = {}) () if not .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_failures ⇒ Object
85 86 87 |
# File 'lib/textquery/textquery.rb', line 85 def terminal_failures @parser.terminal_failures end |