Class: Helium::Element

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

Instance Attribute Summary collapse

Attributes inherited from Resource

#id

Instance Method Summary collapse

Methods inherited from Resource

#==, #created_at, #eql?, #hash, #to_json, #updated_at

Constructor Details

#initialize(client:, params:) ⇒ Element

Returns a new instance of Element



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

def initialize(client:, params:)
  super(client: client, params: params)

  @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



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

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

#update(name:) ⇒ Object

TODO these kinds of methods should be generalized into a Resource object



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

def update(name:)
  @client.update_element(self, name: name)
end