Class: Domotics::Core::ElementGroup
- Inherits:
- BasicObject
- Defined in:
- lib/domotics/core/element_group.rb
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#room ⇒ Object
readonly
Returns the value of attribute room.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #add_element(element) ⇒ Object
-
#initialize(args = {}) ⇒ ElementGroup
constructor
A new instance of ElementGroup.
- #method_missing(method, *args, &block) ⇒ Object
- #respond_to?(method) ⇒ Boolean
- #to_s ⇒ Object
- #verbose_state ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ ElementGroup
Returns a new instance of ElementGroup.
4 5 6 7 8 9 10 11 |
# File 'lib/domotics/core/element_group.rb', line 4 def initialize(args = {}) #::Object.instance_method(:is_a?).bind(self) @name = args[:name] || :undefined @room = Room[args[:room]] @room.register_element self, @name @elements = [] @type = :group end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/domotics/core/element_group.rb', line 24 def method_missing(method, *args, &block) if @elements.map{ |el| el.respond_to? method }.reduce{ |res, n| res && n } @elements.map{ |el| el.public_send method, *args, &block }.reduce{ |res, n| res && n } else super end end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
3 4 5 |
# File 'lib/domotics/core/element_group.rb', line 3 def elements @elements end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/domotics/core/element_group.rb', line 3 def name @name end |
#room ⇒ Object (readonly)
Returns the value of attribute room.
3 4 5 |
# File 'lib/domotics/core/element_group.rb', line 3 def room @room end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/domotics/core/element_group.rb', line 3 def type @type end |
Instance Method Details
#add_element(element) ⇒ Object
12 13 14 |
# File 'lib/domotics/core/element_group.rb', line 12 def add_element(element) @elements << element end |
#respond_to?(method) ⇒ Boolean
31 32 33 |
# File 'lib/domotics/core/element_group.rb', line 31 def respond_to?(method) @elements.map{ |el| el.respond_to? method }.reduce{ |res, n| res && n } || super end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/domotics/core/element_group.rb', line 34 def to_s "Group :#{@name} -> #{@elements}" end |
#verbose_state ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/domotics/core/element_group.rb', line 15 def verbose_state { @room.name => { :elements => { @name => { :state => nil } } } } end |