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



21
22
23
24
25
26
27
# File 'lib/unified2/sensor.rb', line 21

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.



10
11
12
# File 'lib/unified2/sensor.rb', line 10

def checksum
  @checksum
end

#hostnameObject

Returns the value of attribute hostname.



10
11
12
# File 'lib/unified2/sensor.rb', line 10

def hostname
  @hostname
end

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/unified2/sensor.rb', line 10

def id
  @id
end

#interfaceObject

Returns the value of attribute interface.



10
11
12
# File 'lib/unified2/sensor.rb', line 10

def interface
  @interface
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/unified2/sensor.rb', line 10

def name
  @name
end

Instance Method Details

#to_hObject



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

def to_h
  to_hash = {
    :name => name,
    :hostname => hostname,
    :checksum => checksum,
    :id => id,
    :interface => interface
  }
end

#to_sString

To String

Returns:



34
35
36
# File 'lib/unified2/sensor.rb', line 34

def to_s
  @name
end

#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



58
59
60
61
62
63
64
65
66
67
# File 'lib/unified2/sensor.rb', line 58

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