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.
28 29 30 31 32 |
# File 'lib/msfl_visitors/visitor.rb', line 28 def initialize self.mode = :term # or :aggregations self.clauses = Array.new end |
Instance Attribute Details
#clauses ⇒ Object
Returns the value of attribute clauses.
25 26 27 |
# File 'lib/msfl_visitors/visitor.rb', line 25 def clauses @clauses end |
#current_clause ⇒ Object
Returns the value of attribute current_clause.
25 26 27 |
# File 'lib/msfl_visitors/visitor.rb', line 25 def current_clause @current_clause end |
#mode=(value) ⇒ Object
Sets the attribute mode
26 27 28 |
# File 'lib/msfl_visitors/visitor.rb', line 26 def mode=(value) @mode = value end |
Instance Method Details
#get_visitor ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/msfl_visitors/visitor.rb', line 50 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
61 62 63 64 65 66 |
# File 'lib/msfl_visitors/visitor.rb', line 61 def in_aggregation_mode self.mode = :aggregations result = yield if block_given? self.mode = :term result end |
#visit(node) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/msfl_visitors/visitor.rb', line 34 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 |
#visit_tree(root) ⇒ Object
68 69 70 |
# File 'lib/msfl_visitors/visitor.rb', line 68 def visit_tree(root) [{clause: root.accept(self)}].concat(clauses).reject { |c| c[:clause] == "" } end |