Class: TextQuery
- Inherits:
-
Object
- Object
- TextQuery
- Defined in:
- lib/textquery/textquery.rb
Instance Method Summary collapse
- #accept(options = {}, &block) ⇒ Object
- #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.
66 67 68 69 70 71 72 |
# File 'lib/textquery/textquery.rb', line 66 def initialize(query = '', = {}) @parser = TextQueryGrammarParser.new @query = nil () 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( = {}, &block) () if not .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, = {}) () if not .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_failures ⇒ Object
104 105 106 |
# File 'lib/textquery/textquery.rb', line 104 def terminal_failures @parser.terminal_failures end |