Class: VisualizeRuby::Edge

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

Constant Summary

Constants included from Namable

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, 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

#colorObject

Returns the value of attribute color.



13
14
15
# File 'lib/visualize_ruby/edge.rb', line 13

def color
  @color
end

#dirObject (readonly)

Returns the value of attribute dir.



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

def dir
  @dir
end

#displayObject

Returns the value of attribute display.



13
14
15
# File 'lib/visualize_ruby/edge.rb', line 13

def display
  @display
end

#labelObject (readonly)

Returns the value of attribute label.



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

def label
  @label
end

#nodesObject (readonly)

Returns the value of attribute nodes.



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

def nodes
  @nodes
end

#styleObject (readonly)

Returns the value of attribute style.



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

def style
  @style
end

#typeObject (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_symbolObject



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

#hashObject



63
64
65
# File 'lib/visualize_ruby/edge.rb', line 63

def hash
  [dir, name, nodes.map(&:hash), style, color].hash
end

#inspectObject 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_aObject



27
28
29
# File 'lib/visualize_ruby/edge.rb', line 27

def node_a
  nodes[0]
end

#node_bObject



31
32
33
# File 'lib/visualize_ruby/edge.rb', line 31

def node_b
  nodes[1]
end

#to_aObject



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