Class: Machete::Matchers::NodeMatcher

Inherits:
Matcher
  • Object
show all
Defined in:
lib/machete/matchers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class_name, attrs = {}) ⇒ NodeMatcher

Returns a new instance of NodeMatcher.



42
43
44
# File 'lib/machete/matchers.rb', line 42

def initialize(class_name, attrs = {})
  @class_name, @attrs = class_name, attrs
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



40
41
42
# File 'lib/machete/matchers.rb', line 40

def attrs
  @attrs
end

#class_nameObject (readonly)

Returns the value of attribute class_name.



40
41
42
# File 'lib/machete/matchers.rb', line 40

def class_name
  @class_name
end

Instance Method Details

#==(other) ⇒ Object



46
47
48
49
50
# File 'lib/machete/matchers.rb', line 46

def ==(other)
  other.instance_of?(self.class) &&
    @class_name == other.class_name &&
    @attrs == other.attrs
end

#matches?(node) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
# File 'lib/machete/matchers.rb', line 52

def matches?(node)
  node.class == Rubinius::AST.const_get(@class_name) &&
    @attrs.all? { |name, matcher| matcher.matches?(node.send(name)) }
end