Class: VisualizeRuby::Node

Inherits:
Object
  • Object
show all
Includes:
Namable, Optionalable, Touchable
Defined in:
lib/visualize_ruby/node.rb

Constant Summary

Constants included from Namable

VisualizeRuby::Namable::DEFAULT_DISPLAYER

Instance Attribute Summary collapse

Attributes included from Optionalable

#graph_viz_options

Attributes included from Touchable

#touched

Instance Method Summary collapse

Methods included from Optionalable

#options, #post_initialize

Methods included from Touchable

#post_initialize, #step_display, #touch, #touched_display

Methods included from Namable

included, #name, #post_initialize

Constructor Details

#initialize(name: nil, type: :action, style: :rounded, ast: nil, line: nil, id: nil, **opts) ⇒ Node

Returns a new instance of Node.



9
10
11
12
13
14
15
16
# File 'lib/visualize_ruby/node.rb', line 9

def initialize(name: nil, type: :action, style: :rounded, ast: nil, line: nil, id: nil, **opts)
  @label  = name || (ast ? AstHelper.new(ast).description : nil)
  @type  = type
  @style = style
  @id    = id || (ast ? AstHelper.new(ast).id : @label)
  @line  = line || AstHelper.new(ast).first_line
  post_initialize(opts)
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#labelObject (readonly)

Returns the value of attribute label.



7
8
9
# File 'lib/visualize_ruby/node.rb', line 7

def label
  @label
end

#lineObject (readonly)

Returns the value of attribute line.



7
8
9
# File 'lib/visualize_ruby/node.rb', line 7

def line
  @line
end

#lineno_connectionObject

Returns the value of attribute lineno_connection.



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

def lineno_connection
  @lineno_connection
end

#styleObject (readonly)

Returns the value of attribute style.



7
8
9
# File 'lib/visualize_ruby/node.rb', line 7

def style
  @style
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



50
51
52
# File 'lib/visualize_ruby/node.rb', line 50

def ==(other)
  other.class == self.class && other.hash == self.hash
end

#hashObject



56
57
58
# File 'lib/visualize_ruby/node.rb', line 56

def hash
  [type, name, style, id].hash
end

#inspectObject Also known as: to_s



46
47
48
# File 'lib/visualize_ruby/node.rb', line 46

def inspect
  "#<VisualizeRuby::Node #{type_display} #{id}>"
end

#shapeObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/visualize_ruby/node.rb', line 33

def shape
  case type
  when :decision
    :diamond
  when :action
    :ellipse
  when :argument
    :box
  else
    :box
  end
end

#to_aObject



18
19
20
# File 'lib/visualize_ruby/node.rb', line 18

def to_a
  [type, name.to_s]
end

#type_displayObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/visualize_ruby/node.rb', line 22

def type_display
  case type
  when :decision
    "<>"
  when :action
    "[]"
  when :argument
    "[>"
  end
end