Class: GraphViz::Attrs
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #each ⇒ Object
-
#initialize(gviz, name, attributes) ⇒ Attrs
constructor
A new instance of Attrs.
- #to_h ⇒ Object
Constructor Details
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
22 23 24 |
# File 'lib/graphviz/attrs.rb', line 22 def data @data end |
Instance Method Details
#[](key) ⇒ Object
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 |
#[]=(key, value) ⇒ Object
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 |
#each ⇒ Object
31 32 33 34 35 |
# File 'lib/graphviz/attrs.rb', line 31 def each @data.each do |k, v| yield(k, v) end end |
#to_h ⇒ Object
37 38 39 |
# File 'lib/graphviz/attrs.rb', line 37 def to_h @data.clone end |