Class: HueBridge::Color

Inherits:
Object
  • Object
show all
Defined in:
lib/hue_bridge/color.rb

Overview

Value object to represent a color

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Color

Returns a new instance of Color.

Parameters:

  • opts (Hash) (defaults to: {})

    the color options

Options Hash (opts):

  • :bri (Object)

    The brightness

  • :hue (Object)

    The hue

  • :sat (Object)

    The saturation



13
14
15
16
17
18
# File 'lib/hue_bridge/color.rb', line 13

def initialize(opts = {})
  [:bri, :hue, :sat].each do |attr|
    value = opts.fetch(attr, false)
    send("#{attr}=", value) if value
  end
end

Instance Attribute Details

#briObject

Returns the value of attribute bri.



7
8
9
# File 'lib/hue_bridge/color.rb', line 7

def bri
  @bri
end

#hueObject

Returns the value of attribute hue.



7
8
9
# File 'lib/hue_bridge/color.rb', line 7

def hue
  @hue
end

#satObject

Returns the value of attribute sat.



7
8
9
# File 'lib/hue_bridge/color.rb', line 7

def sat
  @sat
end

Instance Method Details

#to_hHash Also known as: to_hash

Returns a hash containing the color options.

Returns:

  • (Hash)

    the options



23
24
25
26
27
28
29
30
# File 'lib/hue_bridge/color.rb', line 23

def to_h
  hash = {}
  [:bri, :hue, :sat].each do |attr|
    value = send(attr)
    hash[attr] = value if value
  end
  hash
end