Class: Unified2::Sensor

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Sensor

Returns a new instance of Sensor.



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

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

Instance Attribute Details

#hostnameObject

Returns the value of attribute hostname.



4
5
6
# File 'lib/unified2/sensor.rb', line 4

def hostname
  @hostname
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/unified2/sensor.rb', line 4

def id
  @id
end

#interfaceObject

Returns the value of attribute interface.



4
5
6
# File 'lib/unified2/sensor.rb', line 4

def interface
  @interface
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/unified2/sensor.rb', line 4

def name
  @name
end

Instance Method Details

#update(attributes = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/unified2/sensor.rb', line 14

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