Class: VisualizeRuby::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/visualize_ruby/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, type: :action, style: :rounded) ⇒ Node

Returns a new instance of Node.



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

def initialize(name:, type: :action, style: :rounded)
  @name  = name.to_s
  @type  = type
  @style = style
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/visualize_ruby/node.rb', line 3

def name
  @name
end

#styleObject (readonly)

Returns the value of attribute style.



3
4
5
# File 'lib/visualize_ruby/node.rb', line 3

def style
  @style
end

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/visualize_ruby/node.rb', line 4

def type
  @type
end

Instance Method Details

#inspectObject Also known as: to_s



38
39
40
# File 'lib/visualize_ruby/node.rb', line 38

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

#shapeObject



29
30
31
32
33
34
35
36
# File 'lib/visualize_ruby/node.rb', line 29

def shape
  case type
  when :decision
    :diamond
  when :action
    :ellipse
  end
end

#to_aObject



16
17
18
# File 'lib/visualize_ruby/node.rb', line 16

def to_a
  [type, name.to_s]
end

#to_symObject



12
13
14
# File 'lib/visualize_ruby/node.rb', line 12

def to_sym
  name.to_s.gsub(" ", "_").to_sym
end

#type_displayObject



20
21
22
23
24
25
26
27
# File 'lib/visualize_ruby/node.rb', line 20

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