class GraphViz::Attrs

Attributes

data[RW]

Public Class Methods

new( gviz, name, attributes ) click to toggle source
# File lib/graphviz/attrs.rb, line 24
def initialize( gviz, name, attributes )
   @name       = name
   @attributes = attributes
   @data       = Hash::new( )
   @graphviz   = gviz
end

Public Instance Methods

[]( key ) click to toggle source
# File lib/graphviz/attrs.rb, line 41
def []( key )
   if key.class == Hash
      key.each do |k, v|
         self[k] = v
      end
   else
      @data[key.to_s]
   end
end
[]=( key, value ) click to toggle source
# File lib/graphviz/attrs.rb, line 51
def []=( key, value )
   unless @attributes.keys.include?( key.to_s )
      raise ArgumentError, "#{@name} attribute '#{key.to_s}' invalid"
   end

   if value.nil?
      warn "Value for attribute `#{key}` can't be null"
      return
   end

   begin
      value = GraphViz::Types.const_get(@attributes[key.to_s]).new(value)
   rescue => e
      raise AttributeException, "Invalid value `#{value}` for attribute `#{key}` : #{e}"
   end

   if value
     @data[key.to_s] = value
     @graphviz.set_position( @name, key.to_s, @data[key.to_s] ) if @graphviz
   end
end
each() { |k, v| ... } click to toggle source
# File lib/graphviz/attrs.rb, line 31
def each
   @data.each do |k, v|
      yield(k, v)
   end
end
to_h() click to toggle source
# File lib/graphviz/attrs.rb, line 37
def to_h
   @data.clone
end