Sha256: af04734dc6ce60bb4b8585bce2206918433dfdbf97fa439187fa5f79a0a98ae1

Contents?: true

Size: 756 Bytes

Versions: 3

Compression:

Stored size: 756 Bytes

Contents

module Helium
  class Label < Resource
    attr_reader :name

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

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

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

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

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

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

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

    # TODO can probably generalize this a bit more
    def as_json
      super.merge({
        name: name
      })
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
helium-ruby-0.23.0 lib/helium/label.rb
helium-ruby-0.22.0 lib/helium/label.rb
helium-ruby-0.21.0 lib/helium/label.rb