Class: Wood::TreePattern::TypeMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/wood/tree_pattern/type_matcher.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_patternObject (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_patternObject (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.[](*options)
  case options.first
  when Hash
    options = options.first
    new(options[:node], options[:type])
  else
    new(*options)
  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

#inspectObject



45
46
47
# File 'lib/wood/tree_pattern/type_matcher.rb', line 45

def inspect
  sexp.inspect
end

#sexpObject



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