Class: VisualizeRuby::Edge
- Inherits:
-
Object
- Object
- VisualizeRuby::Edge
- Includes:
- Namable, Optionalable, Touchable
- Defined in:
- lib/visualize_ruby/edge.rb
Constant Summary
Constants included from Namable
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#display ⇒ Object
Returns the value of attribute display.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes included from Optionalable
Attributes included from Touchable
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #direction_symbol ⇒ Object
- #hash ⇒ Object
-
#initialize(name: nil, nodes:, dir: :forward, type: :default, display: :visual, **opts) ⇒ Edge
constructor
A new instance of Edge.
- #inspect ⇒ Object (also: #to_s)
- #node_a ⇒ Object
- #node_b ⇒ Object
- #to_a ⇒ 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, nodes:, dir: :forward, type: :default, display: :visual, **opts) ⇒ Edge
Returns a new instance of Edge.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/visualize_ruby/edge.rb', line 16 def initialize(name: nil, nodes:, dir: :forward, type: :default, display: :visual, **opts) @label = name.to_s if name @nodes = nodes @dir = dir @style = style @color = color @type = type @display = display post_initialize(opts) end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
13 14 15 |
# File 'lib/visualize_ruby/edge.rb', line 13 def color @color end |
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
7 8 9 |
# File 'lib/visualize_ruby/edge.rb', line 7 def dir @dir end |
#display ⇒ Object
Returns the value of attribute display.
13 14 15 |
# File 'lib/visualize_ruby/edge.rb', line 13 def display @display end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
7 8 9 |
# File 'lib/visualize_ruby/edge.rb', line 7 def label @label end |
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
7 8 9 |
# File 'lib/visualize_ruby/edge.rb', line 7 def nodes @nodes end |
#style ⇒ Object (readonly)
Returns the value of attribute style.
7 8 9 |
# File 'lib/visualize_ruby/edge.rb', line 7 def style @style end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/visualize_ruby/edge.rb', line 7 def type @type end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
57 58 59 |
# File 'lib/visualize_ruby/edge.rb', line 57 def ==(other) other.class == self.class && other.hash == self.hash end |
#direction_symbol ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/visualize_ruby/edge.rb', line 44 def direction_symbol case dir when :forward "->" when :none "-" end end |
#hash ⇒ Object
63 64 65 |
# File 'lib/visualize_ruby/edge.rb', line 63 def hash [dir, name, nodes.map(&:hash), style, color].hash end |
#inspect ⇒ Object Also known as: to_s
53 54 55 |
# File 'lib/visualize_ruby/edge.rb', line 53 def inspect "#<VisualizeRuby::Edge #{to_a.join(" ")}>" end |
#node_a ⇒ Object
27 28 29 |
# File 'lib/visualize_ruby/edge.rb', line 27 def node_a nodes[0] end |
#node_b ⇒ Object
31 32 33 |
# File 'lib/visualize_ruby/edge.rb', line 31 def node_b nodes[1] end |
#to_a ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/visualize_ruby/edge.rb', line 35 def to_a [ node_a.name.to_s, label, direction_symbol, node_b.name.to_s, ].compact end |