File: elements.rb

package info (click to toggle)
ruby-graphviz 1.2.5-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,216 kB
  • sloc: ruby: 7,685; xml: 26; makefile: 17
file content (39 lines) | stat: -rw-r--r-- 776 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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