Class: RBelly::Nodes::Node

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Visitable, Visitors
Defined in:
lib/rbelly/nodes/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Visitable

#accept

Constructor Details

#initialize(value) ⇒ Node

Returns a new instance of Node.



9
10
11
12
13
# File 'lib/rbelly/nodes/node.rb', line 9

def initialize(value)
  @value = value
  @comments = []
  @filename = @line = nil
end

Instance Attribute Details

#commentsObject

Returns the value of attribute comments.



8
9
10
# File 'lib/rbelly/nodes/node.rb', line 8

def comments
  @comments
end

#filenameObject

Returns the value of attribute filename.



8
9
10
# File 'lib/rbelly/nodes/node.rb', line 8

def filename
  @filename
end

#lineObject

Returns the value of attribute line.



8
9
10
# File 'lib/rbelly/nodes/node.rb', line 8

def line
  @line
end

#valueObject

Returns the value of attribute value.



8
9
10
# File 'lib/rbelly/nodes/node.rb', line 8

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object Also known as: =~



15
16
17
# File 'lib/rbelly/nodes/node.rb', line 15

def ==(other)
  other.is_a?(self.class) && @value == other.value
end

#===(other) ⇒ Object



20
21
22
# File 'lib/rbelly/nodes/node.rb', line 20

def ===(other)
  other.is_a?(self.class) && @value === other.value
end

#each(&block) ⇒ Object



71
72
73
# File 'lib/rbelly/nodes/node.rb', line 71

def each(&block)
  EnumerableVisitor.new(block).accept(self)
end

#pointcut(pattern) ⇒ Object Also known as: /



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rbelly/nodes/node.rb', line 24

def pointcut(pattern)
  case pattern
  when String
    ast = RBelly::Parser.new.parse(pattern)
    # Only take the first statement
    finder = ast.value.first.class.to_s =~ /StatementNode$/ ?
      ast.value.first.value : ast.value.first
    visitor = PointcutVisitor.new(finder)
  else
    visitor = PointcutVisitor.new(pattern)
  end

  visitor.accept(self)
  visitor
end

#to_dotsObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rbelly/nodes/node.rb', line 49

def to_dots
  visitor = DotVisitor.new
  visitor.accept(self)
  header = <<-END
digraph g {
graph [ rankdir = "TB" ];
node [
  fontsize = "16"
  shape = "ellipse"
];
edge [ ];
  END
  nodes = visitor.nodes.map { |x| x.to_s }.join("\n")
  counter = 0
  arrows = visitor.arrows.map { |x|
    s = "#{x} [\nid = #{counter}\n];"
    counter += 1
    s
  }.join("\n")
  "#{header}\n#{nodes}\n#{arrows}\n}"
end

#to_ecmaObject



45
46
47
# File 'lib/rbelly/nodes/node.rb', line 45

def to_ecma
  ECMAVisitor.new.accept(self)
end

#to_real_sexpObject



75
76
77
# File 'lib/rbelly/nodes/node.rb', line 75

def to_real_sexp
  RealSexpVisitor.new.accept(self)
end

#to_sexpObject



41
42
43
# File 'lib/rbelly/nodes/node.rb', line 41

def to_sexp
  SexpVisitor.new.accept(self)
end