Sha256: 296ff2f1a08aeab3d44ddcb3ca27df25de0b63591a79b84e63b5cd5ffffcb8f5

Contents?: true

Size: 893 Bytes

Versions: 1

Compression:

Stored size: 893 Bytes

Contents

# frozen_string_literal: true

module Synvert::Core::NodeQuery::Compiler
  # BasicSelector used to match nodes, it combines by node type and/or attribute list.
  class BasicSelector
    # Initialize a BasicSelector.
    # @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 = [".#{@node_type}"]
      result << @attribute_list.to_s if @attribute_list
      result.join('')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
synvert-core-1.4.0 lib/synvert/core/node_query/compiler/basic_selector.rb