Module: Wongi::Engine::NetworkParts::Collectable

Included in:
Wongi::Engine::Network
Defined in:
lib/wongi-engine/network/collectable.rb

Instance Method Summary collapse

Instance Method Details

#add_collector(collector, name) ⇒ Object



19
20
21
# File 'lib/wongi-engine/network/collectable.rb', line 19

def add_collector collector, name
  collectors( name ) << collector
end

#add_error_collectorObject



23
24
25
# File 'lib/wongi-engine/network/collectable.rb', line 23

def add_error_collector
  add_collector collector, :error
end

#collected_tokens(name) ⇒ Object



35
36
37
# File 'lib/wongi-engine/network/collectable.rb', line 35

def collected_tokens name
  collectors( name ).map { |collector| collector.production.tokens }.flatten
end

#collection(name) ⇒ Object



27
28
29
# File 'lib/wongi-engine/network/collectable.rb', line 27

def collection name
  collectors( name ).map( &:default_collect ).flatten.uniq
end

#collectors(name = nil) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/wongi-engine/network/collectable.rb', line 6

def collectors name = nil
  @collectors ||= { }
  if name
    @collectors[name] ||= [ ]
  else
    @collectors
  end
end

#error_collectorsObject



15
16
17
# File 'lib/wongi-engine/network/collectable.rb', line 15

def error_collectors
  collectors :error
end

#errorsObject



31
32
33
# File 'lib/wongi-engine/network/collectable.rb', line 31

def errors
  error_collectors.map( &:errors ).flatten
end