Class: MSFLVisitors::Visitor
- Inherits:
-
Object
- Object
- MSFLVisitors::Visitor
- Defined in:
- lib/msfl_visitors/visitor.rb
Defined Under Namespace
Classes: AggregationsVisitor, ESTermFilterVisitor, TermFilterVisitor
Instance Attribute Summary collapse
-
#clauses ⇒ Object
Returns the value of attribute clauses.
-
#current_clause ⇒ Object
Returns the value of attribute current_clause.
-
#mode ⇒ Object
writeonly
Sets the attribute mode.
Instance Method Summary collapse
- #get_visitor ⇒ Object
- #in_aggregation_mode ⇒ Object
-
#initialize ⇒ Visitor
constructor
A new instance of Visitor.
- #visit(node) ⇒ Object
- #visit_tree(root) ⇒ Object
Constructor Details
#initialize ⇒ Visitor
Returns a new instance of Visitor.
29 30 31 32 33 |
# File 'lib/msfl_visitors/visitor.rb', line 29 def initialize self.mode = :term # or :aggregations self.clauses = Array.new end |
Instance Attribute Details
#clauses ⇒ Object
Returns the value of attribute clauses.
26 27 28 |
# File 'lib/msfl_visitors/visitor.rb', line 26 def clauses @clauses end |
#current_clause ⇒ Object
Returns the value of attribute current_clause.
26 27 28 |
# File 'lib/msfl_visitors/visitor.rb', line 26 def current_clause @current_clause end |
#mode=(value) ⇒ Object
Sets the attribute mode
27 28 29 |
# File 'lib/msfl_visitors/visitor.rb', line 27 def mode=(value) @mode = value end |
Instance Method Details
#get_visitor ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/msfl_visitors/visitor.rb', line 51 def get_visitor case mode when :term TermFilterVisitor.new(self) when :es_term ESTermFilterVisitor.new(self) else AggregationsVisitor.new(self) end end |
#in_aggregation_mode ⇒ Object
62 63 64 65 66 67 |
# File 'lib/msfl_visitors/visitor.rb', line 62 def in_aggregation_mode self.mode = :aggregations result = yield if block_given? self.mode = :term result end |
#visit(node) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/msfl_visitors/visitor.rb', line 35 def visit(node) if mode == :es_term get_visitor.visit(node) else case node when Nodes::Partial in_aggregation_mode do clauses.concat get_visitor.visit(node) "" end else get_visitor.visit(node) end end end |