Class: GraphViz::Attrs

Inherits:
Object
  • Object
show all
Defined in:
lib/graphviz/attrs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gviz, name, attributs) ⇒ Attrs

Returns a new instance of Attrs.



26
27
28
29
30
31
# File 'lib/graphviz/attrs.rb', line 26

def initialize( gviz, name, attributs )
  @name      = name
  @attributs = attributs
  @data      = Hash::new( )
 @graphviz  = gviz
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



24
25
26
# File 'lib/graphviz/attrs.rb', line 24

def data
  @data
end

Instance Method Details

#[](xKey) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/graphviz/attrs.rb', line 43

def []( xKey )
  if xKey.class == Hash
    xKey.each do |k, v|
      self[k] = v
    end
  else
    if @data.key?( xKey.to_s ) == false
      nil
    end
    @data[xKey.to_s]
  end
end

#[]=(xKey, xValue) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/graphviz/attrs.rb', line 56

def []=( xKey, xValue )
  unless @attributs.keys.include?( xKey.to_s )
    raise ArgumentError, "#{@name} attribut '#{xKey.to_s}' invalid"
  end
  
  @data[xKey.to_s] = GraphViz::Types.const_get(@attributs[xKey.to_s]).new( xValue )

  if @graphviz.nil? == false
    @graphviz.set_position( @name, xKey.to_s, @data[xKey.to_s] )
  end
end

#eachObject



33
34
35
36
37
# File 'lib/graphviz/attrs.rb', line 33

def each
  @data.each do |k, v|
    yield(k, v)
  end
end

#to_hObject



39
40
41
# File 'lib/graphviz/attrs.rb', line 39

def to_h
  @data.clone
end