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
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/Yinspire/Dumpers/Dumper_Yin.rb', line 11
def dump(out)
ekeys = @entities.keys.sort
ekeys.each {|key|
entity = @entities[key]
out << "ENTITY " if @verbose
out << to_yin_str(entity.id)
out << " = #{to_yin_str(entity.entity_type)} "
out << to_yin_str(entity.dump)
out << "\n"
}
ekeys.each {|key|
entity = @entities[key]
targets = []; entity.each_connection {|t| targets << to_yin_str(t.id)}
next if targets.empty?
out << "CONNECT " if @verbose
out << "#{to_yin_str(entity.id)} -> #{targets.join(', ')}\n"
}
ekeys.each {|key|
entity = @entities[key]
next unless entity.respond_to?(:stimuli_pq_to_a)
stimuli = entity.stimuli_pq_to_a
next if stimuli.empty?
out << "\n"
out << "STIMULATE " if @verbose
out << "#{to_yin_str(entity.id)} ! {\n "
out << stimuli.to_enum(:each_slice, 2).
map {|at, weight|
if weight == Infinity
to_yin_str(at)
else
"#{to_yin_str(weight)}@#{to_yin_str(at)}"
end
}.to_enum(:each_slice, 5).map {|arr| arr.join(" ")}.join("\n ")
out << "\n}\n"
}
end
|