Class: Vigilem::Core::Hub
- Inherits:
-
Object
- Object
- Vigilem::Core::Hub
- Extended by:
- Support::ObjSpace
- Defined in:
- lib/vigilem/core/hub.rb
Overview
copies events or messages from the system to all the attached buffers except the link, much like a network hub
Instance Attribute Summary collapse
-
#buffers ⇒ Object
readonly
Returns the value of attribute buffers.
-
#group_id ⇒ Object
readonly
Returns the value of attribute group_id.
Class Method Summary collapse
-
.aquire(grp_id) ⇒ Hub
finds a hub based on a group identifier, if no Hub is found a new one is returned.
Instance Method Summary collapse
-
#add_buffer(buffer) ⇒ Object
(also: #<<)
Self is expected like array.
-
#demux(buff, *msgs) ⇒ Array
The buffers that got updated.
-
#initialize(group) ⇒ Hub
constructor
A new instance of Hub.
Constructor Details
#initialize(group) ⇒ Hub
Returns a new instance of Hub.
12 13 14 15 |
# File 'lib/vigilem/core/hub.rb', line 12 def initialize(group) @group_id = group @buffers = [] end |
Instance Attribute Details
#buffers ⇒ Object (readonly)
Returns the value of attribute buffers.
9 10 11 |
# File 'lib/vigilem/core/hub.rb', line 9 def buffers @buffers end |
#group_id ⇒ Object (readonly)
Returns the value of attribute group_id.
9 10 11 |
# File 'lib/vigilem/core/hub.rb', line 9 def group_id @group_id end |
Class Method Details
.aquire(grp_id) ⇒ Hub
finds a hub based on a group identifier, if no Hub is found a new one is returned
45 46 47 |
# File 'lib/vigilem/core/hub.rb', line 45 def aquire(grp_id) all.find {|hub| hub.group_id == grp_id } || obj_register(new(grp_id)) end |
Instance Method Details
#add_buffer(buffer) ⇒ Object Also known as: <<
Returns self is expected like array.
20 21 22 23 |
# File 'lib/vigilem/core/hub.rb', line 20 def add_buffer(buffer) @buffers << buffer self end |
#demux(buff, *msgs) ⇒ Array
Returns the buffers that got updated.
30 31 32 33 34 |
# File 'lib/vigilem/core/hub.rb', line 30 def demux(buff, *msgs) buffers.select do |buffer| buffer.concat(msgs) if (not msgs.empty?) and (not buffer.equal?(buff)) end end |