Class: GraphViz::Attrs
Instance Attribute Summary (collapse)
-
- (Object) data
Returns the value of attribute data.
Instance Method Summary (collapse)
- - (Object) [](key)
- - (Object) []=(key, value)
- - (Object) each
-
- (Attrs) initialize(gviz, name, attributes)
constructor
A new instance of Attrs.
- - (Object) to_h
Constructor Details
- (Attrs) initialize(gviz, name, attributes)
A new instance of Attrs
24 25 26 27 28 29 |
# File 'lib/graphviz/attrs.rb', line 24 def initialize( gviz, name, attributes ) @name = name @attributes = attributes @data = Hash::new( ) @graphviz = gviz end |
Instance Attribute Details
- (Object) data
Returns the value of attribute data
22 23 24 |
# File 'lib/graphviz/attrs.rb', line 22 def data @data end |
Instance Method Details
- (Object) [](key)
41 42 43 44 45 46 47 48 49 |
# 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 |
- (Object) []=(key, value)
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# 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 |
- (Object) each
31 32 33 34 35 |
# File 'lib/graphviz/attrs.rb', line 31 def each @data.each do |k, v| yield(k, v) end end |
- (Object) to_h
37 38 39 |
# File 'lib/graphviz/attrs.rb', line 37 def to_h @data.clone end |