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) ⇒ Node

Returns a new instance of Node.



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

def initialize(name:, type: :action)
  @name = name.to_s
  @type = type
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

#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



36
37
38
# File 'lib/visualize_ruby/node.rb', line 36

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

#shapeObject



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

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

#to_aObject



14
15
16
# File 'lib/visualize_ruby/node.rb', line 14

def to_a
  [type, to_sym]
end

#to_symObject



10
11
12
# File 'lib/visualize_ruby/node.rb', line 10

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

#type_displayObject



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

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