Class: Helium::Element

Inherits:
Resource show all
Defined in:
lib/helium/element.rb

Instance Attribute Summary collapse

Attributes inherited from Resource

#id, #type

Instance Method Summary collapse

Methods inherited from Resource

#==, all, create, #created_at, #destroy, #eql?, find, #hash, #to_json, #update, #updated_at

Constructor Details

#initialize(opts = {}) ⇒ Element

Returns a new instance of Element



5
6
7
8
9
10
11
# File 'lib/helium/element.rb', line 5

def initialize(opts = {})
  super(opts)

  @name     = @params.dig("attributes", "name")
  @mac      = @params.dig("meta", "mac")
  @versions = @params.dig("meta", "versions")
end

Instance Attribute Details

#macObject (readonly)

Returns the value of attribute mac



3
4
5
# File 'lib/helium/element.rb', line 3

def mac
  @mac
end

#nameObject (readonly)

Returns the value of attribute name



3
4
5
# File 'lib/helium/element.rb', line 3

def name
  @name
end

#versionsObject (readonly)

Returns the value of attribute versions



3
4
5
# File 'lib/helium/element.rb', line 3

def versions
  @versions
end

Instance Method Details

#as_jsonObject

TODO can probably generalize this a bit more



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

def as_json
  super.merge({
    name: name,
    mac: mac,
    versions: versions
  })
end

#sensorsObject



13
14
15
# File 'lib/helium/element.rb', line 13

def sensors
  @client.element_sensors(self)
end