Class: Dusen::Syntax
- Inherits:
-
Object
- Object
- Dusen::Syntax
- Defined in:
- lib/dusen/syntax.rb
Instance Method Summary collapse
- #fields ⇒ Object
-
#initialize ⇒ Syntax
constructor
A new instance of Syntax.
- #learn_field(field, &scoper) ⇒ Object
- #learn_unknown_field(&unknown_scoper) ⇒ Object
- #parse(query) ⇒ Object
- #search(root_scope, query) ⇒ Object
Constructor Details
#initialize ⇒ Syntax
Returns a new instance of Syntax.
6 7 8 |
# File 'lib/dusen/syntax.rb', line 6 def initialize @scopers = {} end |
Instance Method Details
#fields ⇒ Object
30 31 32 |
# File 'lib/dusen/syntax.rb', line 30 def fields @scopers end |
#learn_field(field, &scoper) ⇒ Object
10 11 12 13 |
# File 'lib/dusen/syntax.rb', line 10 def learn_field(field, &scoper) field = field.to_s @scopers[field] = scoper end |
#learn_unknown_field(&unknown_scoper) ⇒ Object
15 16 17 |
# File 'lib/dusen/syntax.rb', line 15 def learn_unknown_field(&unknown_scoper) @unknown_scoper = unknown_scoper end |
#parse(query) ⇒ Object
34 35 36 |
# File 'lib/dusen/syntax.rb', line 34 def parse(query) Parser.parse(query) end |
#search(root_scope, query) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dusen/syntax.rb', line 19 def search(root_scope, query) scope = root_scope query = parse(query) if query.is_a?(String) query = query.condensed query.each do |token| scoper = @scopers[token.field] || unknown_scoper scope = scoper.call(scope, token.value) end scope end |