Class: VisualizeRuby::Node
- Inherits:
-
Object
- Object
- VisualizeRuby::Node
- 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
-
#id ⇒ Object
Returns the value of attribute id.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#lineno_connection ⇒ Object
Returns the value of attribute lineno_connection.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes included from Optionalable
Attributes included from Touchable
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(name: nil, type: :action, style: :rounded, ast: nil, line: nil, id: nil, **opts) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object (also: #to_s)
- #shape ⇒ Object
- #to_a ⇒ Object
- #type_display ⇒ Object
Methods included from Optionalable
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
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/visualize_ruby/node.rb', line 8 def id @id end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
7 8 9 |
# File 'lib/visualize_ruby/node.rb', line 7 def label @label end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
7 8 9 |
# File 'lib/visualize_ruby/node.rb', line 7 def line @line end |
#lineno_connection ⇒ Object
Returns the value of attribute lineno_connection.
8 9 10 |
# File 'lib/visualize_ruby/node.rb', line 8 def lineno_connection @lineno_connection end |
#style ⇒ Object (readonly)
Returns the value of attribute style.
7 8 9 |
# File 'lib/visualize_ruby/node.rb', line 7 def style @style end |
#type ⇒ Object
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 |
#hash ⇒ Object
56 57 58 |
# File 'lib/visualize_ruby/node.rb', line 56 def hash [type, name, style, id].hash end |
#inspect ⇒ Object Also known as: to_s
46 47 48 |
# File 'lib/visualize_ruby/node.rb', line 46 def inspect "#<VisualizeRuby::Node #{type_display} #{id}>" end |
#shape ⇒ Object
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_a ⇒ Object
18 19 20 |
# File 'lib/visualize_ruby/node.rb', line 18 def to_a [type, name.to_s] end |
#type_display ⇒ Object
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 |