Class: ColorCode::HSV
- Inherits:
-
Object
- Object
- ColorCode::HSV
- Defined in:
- lib/color_code/hsv.rb
Instance Attribute Summary collapse
-
#h ⇒ Object
Returns the value of attribute h.
-
#s ⇒ Object
Returns the value of attribute s.
-
#v ⇒ Object
Returns the value of attribute v.
Instance Method Summary collapse
-
#initialize(code = nil, h: 0, s: 0, v: 0) ⇒ HSV
constructor
A new instance of HSV.
- #to_a ⇒ Object
- #to_hash ⇒ Object
- #to_rgb ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(code = nil, h: 0, s: 0, v: 0) ⇒ HSV
Returns a new instance of HSV.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/color_code/hsv.rb', line 5 def initialize(code=nil, h: 0, s: 0, v: 0) if code hsv = ColorCode::RGB.new(code).to_hsv h, s, v = hsv.to_a end @h = h @s = s @v = v raise if @h > 360 || @s > 100 || @v > 100 rescue raise ArgumentError.new('invalid value') end |
Instance Attribute Details
#h ⇒ Object
Returns the value of attribute h.
3 4 5 |
# File 'lib/color_code/hsv.rb', line 3 def h @h end |
#s ⇒ Object
Returns the value of attribute s.
3 4 5 |
# File 'lib/color_code/hsv.rb', line 3 def s @s end |
#v ⇒ Object
Returns the value of attribute v.
3 4 5 |
# File 'lib/color_code/hsv.rb', line 3 def v @v end |
Instance Method Details
#to_a ⇒ Object
24 25 26 |
# File 'lib/color_code/hsv.rb', line 24 def to_a [@h, @s, @v] end |
#to_hash ⇒ Object
28 29 30 |
# File 'lib/color_code/hsv.rb', line 28 def to_hash { h: @h, s: @s, v: @v } end |
#to_rgb ⇒ Object
32 33 34 35 |
# File 'lib/color_code/hsv.rb', line 32 def to_rgb r, g, b = convert_rgb ColorCode::RGB.new(r: r, g: g, b: b) end |
#to_s ⇒ Object
19 20 21 22 |
# File 'lib/color_code/hsv.rb', line 19 def to_s rgb = convert_rgb.map { |hue| '%02x' % hue }.join "##{rgb}" end |