class HueBridge::Color
Value object to represent a color
Attributes
bri[R]
hue[R]
sat[R]
Public Class Methods
new(opts = {})
click to toggle source
@param opts [Hash] the color options @option opts :bri The brightness @option opts :hue The hue @option opts :sat The saturation
# 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
Public Instance Methods
bri=(value)
click to toggle source
Sets the brightness. Only values between 1 and 254 are allowed. @param [Integer] value
# File lib/hue_bridge/color.rb, line 52 def bri=(value) fail InvalidColorOption, 'Invalid brightness' unless value.between?(1, 254) @bri = value end
hue=(value)
click to toggle source
Sets the hue. Only values between 0 and 65535 are allowed. @param [Integer] value
# File lib/hue_bridge/color.rb, line 36 def hue=(value) fail InvalidColorOption, 'Invalid hue' unless value.between?(0, 65535) @hue = value end
sat=(value)
click to toggle source
Sets the saturation. Only values between 0 and 254 are allowed. @param [Integer] value
# File lib/hue_bridge/color.rb, line 44 def sat=(value) fail InvalidColorOption, 'Invalid saturation' unless value.between?(0, 254) @sat = value end
to_h()
click to toggle source
Returns a hash containing the color options.
@return [Hash] the options
# 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
Also aliased as: to_hash