Class: Domotics::Core::Device

Inherits:
Object
  • Object
show all
Defined in:
lib/domotics/core/device.rb

Direct Known Subclasses

ArduinoBoard, FileCameraDevice

Constant Summary collapse

@@devices =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Device

Returns a new instance of Device.



5
6
7
8
9
# File 'lib/domotics/core/device.rb', line 5

def initialize(args = {})
  @name = args[:name] || SecureRandom.hex
  @@devices[@name] = self
  @type = args[:type] || "undefined"
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/domotics/core/device.rb', line 4

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/domotics/core/device.rb', line 4

def type
  @type
end

Class Method Details

.[](symbol = nil) ⇒ Object



11
12
13
14
# File 'lib/domotics/core/device.rb', line 11

def self.[](symbol = nil)
  return @@devices[symbol] if symbol
  @@devices
end

Instance Method Details

#destroyObject



16
17
18
# File 'lib/domotics/core/device.rb', line 16

def destroy
  @@devices[@name] = nil
end

#to_sObject



19
20
21
# File 'lib/domotics/core/device.rb', line 19

def to_s
  "Room[#{@name}](id:#{__id__})"
end