Class: Helium::Label

Inherits:
Resource show all
Defined in:
lib/helium/label.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:) ⇒ Label

Returns a new instance of Label



5
6
7
8
9
# File 'lib/helium/label.rb', line 5

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

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name



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

def name
  @name
end

Instance Method Details

#add_sensors(sensors_to_add = []) ⇒ Object



25
26
27
28
29
# File 'lib/helium/label.rb', line 25

def add_sensors(sensors_to_add = [])
  sensors_to_add = Array(sensors_to_add)

  @client.update_label_sensors(self, sensors: sensors + sensors_to_add)
end

#as_jsonObject

TODO can probably generalize this a bit more



38
39
40
41
42
# File 'lib/helium/label.rb', line 38

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

#destroyObject



15
16
17
# File 'lib/helium/label.rb', line 15

def destroy
  @client.delete_label(self)
end

#remove_sensors(sensors_to_remove = []) ⇒ Object



31
32
33
34
35
# File 'lib/helium/label.rb', line 31

def remove_sensors(sensors_to_remove = [])
  sensors_to_remove = Array(sensors_to_remove)

  @client.update_label_sensors(self, sensors: sensors - sensors_to_remove)
end

#sensorsObject

TODO: would be nice to wrap this in a proxy collection, that way we could do something like label.sensors << new_sensor



21
22
23
# File 'lib/helium/label.rb', line 21

def sensors
  @client.label_sensors(self)
end

#update(name:) ⇒ Object



11
12
13
# File 'lib/helium/label.rb', line 11

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