Class: Machete::Matchers::NodeMatcher
- Defined in:
- lib/machete/matchers.rb
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
-
#class_name ⇒ Object
readonly
Returns the value of attribute class_name.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(class_name, attrs = {}) ⇒ NodeMatcher
constructor
A new instance of NodeMatcher.
- #matches?(node) ⇒ Boolean
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
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
40 41 42 |
# File 'lib/machete/matchers.rb', line 40 def attrs @attrs end |
#class_name ⇒ Object (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
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 |