Class: VisualizeRuby::Edge

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, nodes:, dir: :forward, style: :solid, color: nil) ⇒ Edge



10
11
12
13
14
15
16
17
# File 'lib/visualize_ruby/edge.rb', line 10

def initialize(name: nil, nodes:, dir: :forward, style: :solid, color: nil)
  @name   = name.to_s if name
  @node_a = nodes[0]
  @node_b = nodes[1]
  @dir    = dir
  @style  = style
  @color  = color
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



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

def color
  @color
end

#dirObject (readonly)

Returns the value of attribute dir.



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

def dir
  @dir
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#node_aObject (readonly)

Returns the value of attribute node_a.



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

def node_a
  @node_a
end

#node_bObject (readonly)

Returns the value of attribute node_b.



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

def node_b
  @node_b
end

#styleObject (readonly)

Returns the value of attribute style.



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

def style
  @style
end

Instance Method Details

#direction_symbolObject



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

def direction_symbol
  case dir
  when :forward
    "->"
  when :none
    "-"
  end
end

#inspectObject Also known as: to_s



37
38
39
# File 'lib/visualize_ruby/edge.rb', line 37

def inspect
  "#<VisualizeRuby::Edge #{to_a.join(" ")}>"
end

#to_aObject



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

def to_a
  [
      node_a.name.to_s,
      name,
      direction_symbol,
      node_b.name.to_s,
  ].compact
end