Sha256: bc564fe7e1c1a6751be5779b35397f6b31c055a40a7ab3ee57bfdb35fcb33283

Contents?: true

Size: 798 Bytes

Versions: 13

Compression:

Stored size: 798 Bytes

Contents

class GraphViz
  class Elements
    def initialize
      @elements = Array.new
      @elements_hash_by_type = Hash.new
    end
    
    def push( obj )
      @elements.push( obj )
      if @elements_hash_by_type[obj['type']].nil?
        @elements_hash_by_type[obj['type']] = Array.new
      end
      
      @elements_hash_by_type[obj['type']].push( obj )
    end
    
    def each( &b )
      @elements.each do |e|
        yield( e )
      end
    end
    
    def size_of( type )
      if @elements_hash_by_type[type].nil?
        return 0
      else
        return @elements_hash_by_type[type].size
      end
    end
    
    def []( index, type = nil )
      if type.nil?
        return @elements[index]
      else
        return @elements_hash_by_type[type][index]
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ruby-graphviz-1.0.7 lib/graphviz/elements.rb
ruby-graphviz-1.0.6 lib/graphviz/elements.rb
ruby-graphviz-1.0.5 lib/graphviz/elements.rb
ruby-graphviz-1.0.4 lib/graphviz/elements.rb
ruby-graphviz-1.0.3 lib/graphviz/elements.rb
ruby-graphviz-1.0.2 lib/graphviz/elements.rb
ruby-graphviz-1.0.1 lib/graphviz/elements.rb
ruby-graphviz-1.0.0 lib/graphviz/elements.rb
ruby-graphviz-0.9.21 lib/graphviz/elements.rb
ruby-graphviz-0.9.20 lib/graphviz/elements.rb
ruby-graphviz-0.9.19 lib/graphviz/elements.rb
ruby-graphviz-0.9.18 lib/graphviz/elements.rb
ruby-graphviz-0.9.17 lib/graphviz/elements.rb