Class: Helium::Label

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

Instance Attribute Summary collapse

Attributes inherited from Resource

#id, #params, #type

Instance Method Summary collapse

Methods inherited from Resource

#==, all, all_path, create, #created_at, #destroy, #eql?, find, #hash, initialize_from_path, #metadata, resource_name, #resource_name, #resource_path, singleton, #to_json, #update, #updated_at

Methods included from Utils

#datetime_to_iso, #kebab_case

Constructor Details

#initialize(opts = {}) ⇒ Label

Returns a new instance of Label



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

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

  @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



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

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



28
29
30
31
32
# File 'lib/helium/label.rb', line 28

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

#remove_sensors(sensors_to_remove = []) ⇒ Object



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

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



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

def sensors
  Collection.new(klass: Sensor, client: @client, belongs_to: self)
end