Class: HueBridge::Color
- Inherits:
-
Object
- Object
- HueBridge::Color
- Defined in:
- lib/hue_bridge/color.rb
Overview
Value object to represent a color
Instance Attribute Summary collapse
-
#bri ⇒ Object
Returns the value of attribute bri.
-
#hue ⇒ Object
Returns the value of attribute hue.
-
#sat ⇒ Object
Returns the value of attribute sat.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Color
constructor
A new instance of Color.
-
#to_h ⇒ Hash
(also: #to_hash)
Returns a hash containing the color options.
Constructor Details
#initialize(opts = {}) ⇒ Color
Returns a new instance of Color.
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
#bri ⇒ Object
Returns the value of attribute bri.
7 8 9 |
# File 'lib/hue_bridge/color.rb', line 7 def bri @bri end |
#hue ⇒ Object
Returns the value of attribute hue.
7 8 9 |
# File 'lib/hue_bridge/color.rb', line 7 def hue @hue end |
#sat ⇒ Object
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_h ⇒ Hash Also known as: to_hash
Returns a hash containing the color 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 |