Class: HomeAssistant::Generator::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/home_assistant/generator/component.rb

Overview

generic home-assistant component

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Component

Returns a new instance of Component.



9
10
11
12
# File 'lib/home_assistant/generator/component.rb', line 9

def initialize(name)
  @properties = Mash.new
  send(name_property, name)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/home_assistant/generator/component.rb', line 22

def method_missing(name, *args)
  super unless args.one?

  properties[name.to_sym] = case args.first
                            when Symbol
                              args.first.to_s
                            else
                              args.first
                            end
end

Instance Attribute Details

#component_classObject

Returns the value of attribute component_class.



8
9
10
# File 'lib/home_assistant/generator/component.rb', line 8

def component_class
  @component_class
end

#propertiesObject (readonly)

Returns the value of attribute properties.



7
8
9
# File 'lib/home_assistant/generator/component.rb', line 7

def properties
  @properties
end

Instance Method Details

#name_propertyObject



14
15
16
# File 'lib/home_assistant/generator/component.rb', line 14

def name_property
  :name
end

#to_hObject



18
19
20
# File 'lib/home_assistant/generator/component.rb', line 18

def to_h
  properties.to_hash
end