Class: Wood::TreePattern::TypeMatcher
- Inherits:
-
Object
- Object
- Wood::TreePattern::TypeMatcher
- Defined in:
- lib/wood/tree_pattern/type_matcher.rb
Instance Attribute Summary collapse
-
#node_pattern ⇒ Object
readonly
Returns the value of attribute node_pattern.
-
#type_pattern ⇒ Object
readonly
Returns the value of attribute type_pattern.
Class Method Summary collapse
Instance Method Summary collapse
- #==(node) ⇒ Object
- #===(node) ⇒ Object
-
#initialize(node_pattern, type_pattern) ⇒ TypeMatcher
constructor
A new instance of TypeMatcher.
- #inspect ⇒ Object
- #sexp ⇒ Object
Constructor Details
#initialize(node_pattern, type_pattern) ⇒ TypeMatcher
Returns a new instance of TypeMatcher.
14 15 16 17 |
# File 'lib/wood/tree_pattern/type_matcher.rb', line 14 def initialize(node_pattern, type_pattern) @node_pattern = node_pattern || AnyMatcher.new @type_pattern = type_pattern end |
Instance Attribute Details
#node_pattern ⇒ Object (readonly)
Returns the value of attribute node_pattern.
13 14 15 |
# File 'lib/wood/tree_pattern/type_matcher.rb', line 13 def node_pattern @node_pattern end |
#type_pattern ⇒ Object (readonly)
Returns the value of attribute type_pattern.
13 14 15 |
# File 'lib/wood/tree_pattern/type_matcher.rb', line 13 def type_pattern @type_pattern end |
Class Method Details
.[](*options) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/wood/tree_pattern/type_matcher.rb', line 3 def self.[](*) case .first when Hash = .first new([:node], [:type]) else new(*) end end |
Instance Method Details
#==(node) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/wood/tree_pattern/type_matcher.rb', line 27 def == node val = @node_pattern == node if val && (@type_pattern == type(node)) return val end return nil end |
#===(node) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/wood/tree_pattern/type_matcher.rb', line 19 def === node val = @node_pattern === node if val && (@type_pattern === type(node)) return val end return nil end |
#inspect ⇒ Object
45 46 47 |
# File 'lib/wood/tree_pattern/type_matcher.rb', line 45 def inspect sexp.inspect end |
#sexp ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/wood/tree_pattern/type_matcher.rb', line 35 def sexp node_pat_sexp = if @node_pattern.respond_to?(:sexp) @node_pattern.sexp else @node_pattern.to_s end [:type_matcher, node_pat_sexp, @type_pattern.sexp] end |