Class: Domotics::Core::ElementGroup

Inherits:
BasicObject
Defined in:
lib/domotics/core/element_group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#elementsObject (readonly)

Returns the value of attribute elements.



3
4
5
# File 'lib/domotics/core/element_group.rb', line 3

def elements
  @elements
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/domotics/core/element_group.rb', line 3

def name
  @name
end

#roomObject (readonly)

Returns the value of attribute room.



3
4
5
# File 'lib/domotics/core/element_group.rb', line 3

def room
  @room
end

#typeObject (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

Returns:

  • (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_sObject



34
35
36
# File 'lib/domotics/core/element_group.rb', line 34

def to_s
  "Group :#{@name} -> #{@elements}"
end

#verbose_stateObject



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