Class: KQL::Filter
- Inherits:
-
Object
- Object
- KQL::Filter
- Defined in:
- lib/kql/filter.rb
Instance Attribute Summary collapse
-
#matchers ⇒ Object
readonly
Returns the value of attribute matchers.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #execute(context) ⇒ Object
-
#initialize(node: nil, tag: nil, matchers: []) ⇒ Filter
constructor
A new instance of Filter.
Constructor Details
#initialize(node: nil, tag: nil, matchers: []) ⇒ Filter
Returns a new instance of Filter.
5 6 7 8 9 |
# File 'lib/kql/filter.rb', line 5 def initialize(node: nil, tag: nil, matchers: []) @node = node @tag = tag @matchers = matchers end |
Instance Attribute Details
#matchers ⇒ Object (readonly)
Returns the value of attribute matchers.
3 4 5 |
# File 'lib/kql/filter.rb', line 3 def matchers @matchers end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
3 4 5 |
# File 'lib/kql/filter.rb', line 3 def node @node end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
3 4 5 |
# File 'lib/kql/filter.rb', line 3 def tag @tag end |
Instance Method Details
#==(other) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/kql/filter.rb', line 11 def ==(other) return false unless other.is_a?(Filter) other.node == node && other.tag == tag && other.matchers == matchers end |
#execute(context) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/kql/filter.rb', line 19 def execute(context) selected_nodes = [] context.selected_nodes.flat_map do |n| selected_nodes << n if match?(n.node) selected_nodes += filter_nodes(n.node.children, n.node) unless n.stop end Query::Context.new(selected_nodes) end |