Class: NeuralEntity

Inherits:
Object
  • Object
show all
Defined in:
lib/Yinspire/Core/NeuralEntity.rb,
lib/Yinspire.rb,
lib/Yinspire/Core/Scheduling/NeuralEntity.rb

Overview

Extends class NeuralEntity for methods related to scheduling.

Direct Known Subclasses

Neuron, Synapse

Constant Summary collapse

@@entity_type_map =

Entity type name to class mapping.

Hash.new
@@entity_type_map_reverse =

Entity class to type name mapping.

Hash.new
@@entity_ann_load_cache =

Annotation cache for loading entities.

Hash.new
@@entity_ann_dump_cache =

Annotation cache for dumping entities.

Hash.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id = nil, simulator = nil, &block) ⇒ NeuralEntity

Returns a new instance of NeuralEntity.



62
63
64
65
66
# File 'lib/Yinspire/Core/NeuralEntity.rb', line 62

def initialize(id=nil, simulator=nil, &block)
  self.id = id
  self.simulator = simulator
  block.call(self) if block
end

Class Method Details

.class_from_name(name) ⇒ Object



41
42
43
# File 'lib/Yinspire/Core/NeuralEntity.rb', line 41

def self.class_from_name(name)
  (@@entity_type_map[name] || raise(ArgumentError))
end

.entity_ann_dump_cacheObject



35
# File 'lib/Yinspire/Core/NeuralEntity.rb', line 35

def self.entity_ann_dump_cache() @@entity_ann_dump_cache end

.entity_ann_load_cacheObject



29
# File 'lib/Yinspire/Core/NeuralEntity.rb', line 29

def self.entity_ann_load_cache() @@entity_ann_load_cache end

.entity_type_mapObject



14
# File 'lib/Yinspire/Core/NeuralEntity.rb', line 14

def self.entity_type_map() @@entity_type_map end

.entity_type_map_reverseObject



21
# File 'lib/Yinspire/Core/NeuralEntity.rb', line 21

def self.entity_type_map_reverse() @@entity_type_map_reverse end

.new_from_name(name, *args, &block) ⇒ Object



37
38
39
# File 'lib/Yinspire/Core/NeuralEntity.rb', line 37

def self.new_from_name(name, *args, &block)
  (@@entity_type_map[name] || raise(ArgumentError)).new(*args, &block)
end

Instance Method Details

#connect(target) ⇒ Object

Connect self with target.



88
# File 'lib/Yinspire/Core/NeuralEntity.rb', line 88

def connect(target) raise "abstract method" end

#disconnect(target) ⇒ Object

Disconnect self from all connections.



93
# File 'lib/Yinspire/Core/NeuralEntity.rb', line 93

def disconnect(target) raise "abstract method" end

#disconnect_allObject

Disconnect self from all connections.



103
104
105
# File 'lib/Yinspire/Core/NeuralEntity.rb', line 103

def disconnect_all
  each_connection {|conn| disconnect(conn) }
end

#dumpObject



54
55
56
57
58
59
60
# File 'lib/Yinspire/Core/NeuralEntity.rb', line 54

def dump
  hash = Hash.new
  @@entity_ann_dump_cache[self.class].each {|key|
    hash[key] = send(key)
  }
  hash
end

#each_connectionObject

Iterates over each connection. To be overwritten by subclasses!



98
# File 'lib/Yinspire/Core/NeuralEntity.rb', line 98

def each_connection() raise "abstract method" end

#entity_typeObject



23
# File 'lib/Yinspire/Core/NeuralEntity.rb', line 23

def entity_type() @@entity_type_map_reverse[self.class] end

#load(hash) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/Yinspire/Core/NeuralEntity.rb', line 45

def load(hash)
  a = @@entity_ann_load_cache[self.class]
  hash.each {|key, value|
    if meth = a[key]
      send(meth, value)
    end
  }
end