Sha256: c2ec93024a542df496dd862cad3b974e237c3500dbe26db52b6c30bdd7de9019
Contents?: true
Size: 927 Bytes
Versions: 2
Compression:
Stored size: 927 Bytes
Contents
# frozen_string_literal: true module Synvert::Core::NodeQuery::Compiler # SimpleSelector used to match nodes, it combines by node type and/or attribute list. class SimpleSelector # Initialize a SimpleSelector. # @param node_type [String] the node type # @param attribute_list [Synvert::Core::NodeQuery::Compiler::AttributeList] the attribute list def initialize(node_type:, attribute_list: nil) @node_type = node_type @attribute_list = attribute_list end # Check if node matches the selector. # @param node [Parser::AST::Node] the node def match?(node, _operator = '==') return false unless node @node_type.to_sym == node.type && (!@attribute_list || @attribute_list.match?(node)) end def to_s result = [] result << ".#{@node_type}" if @node_type result << @attribute_list.to_s if @attribute_list result.join('') end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
synvert-core-1.3.1 | lib/synvert/core/node_query/compiler/simple_selector.rb |
synvert-core-1.3.0 | lib/synvert/core/node_query/compiler/simple_selector.rb |