Class: Hash

Inherits:
Object show all
Includes:
TSort
Defined in:
lib/ttk/symtbl.rb,
lib/ttk/loaders/Loader.rb,
lib/ttk/logger/to_ttk_log.rb,
lib/ttk/strategies/PackageCollection.rb

Direct Known Subclasses

OHash

Instance Method Summary collapse

Instance Method Details

#hash_to_ttk_log(log, type) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ttk/logger/to_ttk_log.rb', line 32

def hash_to_ttk_log ( log, type )
  each do |k,v|
    if v.is_a? Array and v.all? { |x| x.is_a? Hash }
      log.new_node(k, :seq) do
        v.each do |x|
          x.to_ttk_log(log)
        end
      end
    else
      log.new_node(k, type) do
        v.to_ttk_log(log)
      end
    end
  end
end

#symtbl_gsub(symtbl) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ttk/symtbl.rb', line 57

def symtbl_gsub ( symtbl )
  changed = false
  res = self.class.new
  each do |k,v|
    new_k = k.symtbl_gsub(symtbl)
    new_v = v.symtbl_gsub(symtbl)
    changed = true if new_k or new_v
    res[new_k || k] = (new_v || v)
  end
  changed ? res : nil
end

#testify(opts = {}, &block) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/ttk/loaders/Loader.rb', line 124

def testify ( opts={}, &block )

  if size == 1 and (tab = to_a[0])[1].is_a? Hash
    name, doc = tab
    doc[:name] = name
    return doc.testify(opts, &block)
  end

  strategy = self[:strategy] || opts[:strategy]

  if strategy.nil?
    raise ArgumentError, "no strategy for this test (#{inspect})"
  end

  TTK::Loaders.get_class(strategy).new do |t|
    block[t] if block_given?
    t.assign(self)
  end

end

#to_ttk_log(log) ⇒ Object



48
49
50
# File 'lib/ttk/logger/to_ttk_log.rb', line 48

def to_ttk_log ( log )
  hash_to_ttk_log(log, :map)
end

#tsort_each_child(node, &block) ⇒ Object



56
57
58
# File 'lib/ttk/strategies/PackageCollection.rb', line 56

def tsort_each_child(node, &block)
  fetch(node).each(&block)
end

#tsort_each_from(node = nil, &block) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/ttk/strategies/PackageCollection.rb', line 60

def tsort_each_from ( node=nil, &block )
  return tsort_each(&block) if node.nil?
  each_strongly_connected_component_from(node) do |component|
    if component.size == 1
      block[component.first]
    else
      raise Cyclic, "topological sort failed: #{component.inspect}"
    end
  end
end

#tsort_from(node = nil) ⇒ Object



71
72
73
74
75
76
# File 'lib/ttk/strategies/PackageCollection.rb', line 71

def tsort_from ( node=nil )
  return tsort if node.nil?
  result = []
  tsort_each_from(node) { |n| result << n }
  result
end