Class: Unified2::Sensor

Inherits:
Object
  • Object
show all
Defined in:
lib/unified2/sensor.rb

Overview

Sensor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Sensor

Initialize sensor object

Parameters:

  • options (Hash) (defaults to: {})

    Sensor hash attributes

Options Hash (options):

  • :id (Integer)

    Sensor id

  • :name (String)

    Sensor name

  • :interface (String)

    Sensor interface



18
19
20
21
22
23
24
# File 'lib/unified2/sensor.rb', line 18

def initialize(options={})
  @id = options[:id] || 0
  @name = options[:name] || ""
  @hostname ||= Socket.gethostname
  @interface ||= options[:interface] || nil
  @checksum = nil
end

Instance Attribute Details

#checksumObject

Returns the value of attribute checksum.



7
8
9
# File 'lib/unified2/sensor.rb', line 7

def checksum
  @checksum
end

#hostnameObject

Returns the value of attribute hostname.



7
8
9
# File 'lib/unified2/sensor.rb', line 7

def hostname
  @hostname
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/unified2/sensor.rb', line 7

def id
  @id
end

#interfaceObject

Returns the value of attribute interface.



7
8
9
# File 'lib/unified2/sensor.rb', line 7

def interface
  @interface
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/unified2/sensor.rb', line 7

def name
  @name
end

Instance Method Details

#update(attributes = {}) ⇒ Object

Update

Parameters:

  • attributes (Hash) (defaults to: {})

    Sensor attributes

Options Hash (attributes):

  • :id (Integer)

    Sensor id

  • :hostname (String)

    Sensor hostname

  • :name (String)

    Sensor name

  • :interface (String)

    Sensor interface



36
37
38
39
40
41
42
43
44
45
# File 'lib/unified2/sensor.rb', line 36

def update(attributes={})
  return self if attributes.empty?
  
  attributes.each do |key, value|
    next unless self.respond_to?(key.to_sym)
    instance_variable_set(:"@#{key}", value)
  end
  
  self
end