Class: Colorable::HSB
- Inherits:
-
ColorSpace
- Object
- ColorSpace
- Colorable::HSB
- Defined in:
- lib/colorable/color_space.rb
Instance Attribute Summary collapse
-
#b ⇒ Object
(also: #bright)
Returns the value of attribute b.
-
#h ⇒ Object
(also: #hue)
Returns the value of attribute h.
-
#hsb ⇒ Object
(also: #to_a)
Returns the value of attribute hsb.
-
#s ⇒ Object
(also: #sat)
Returns the value of attribute s.
Instance Method Summary collapse
-
#+(arg) ⇒ Object
Pass Array of [h, s, b] or a Fixnum.
-
#initialize(h = 0, s = 0, b = 0) ⇒ HSB
constructor
A new instance of HSB.
- #to_hex ⇒ Object
- #to_name ⇒ Object
- #to_rgb ⇒ Object
Methods inherited from ColorSpace
#-, #<=>, #coerce, #move_to_top, #to_s
Methods included from Converter
#hex2rgb, #hsb2rgb, #name2rgb, #rgb2hex, #rgb2hsb, #rgb2hsl, #rgb2name
Constructor Details
#initialize(h = 0, s = 0, b = 0) ⇒ HSB
Returns a new instance of HSB.
135 136 137 |
# File 'lib/colorable/color_space.rb', line 135 def initialize(h=0,s=0,b=0) @h, @s, @b = @hsb = validate_hsb([h, s, b]) end |
Instance Attribute Details
#b ⇒ Object Also known as: bright
Returns the value of attribute b.
134 135 136 |
# File 'lib/colorable/color_space.rb', line 134 def b @b end |
#h ⇒ Object Also known as: hue
Returns the value of attribute h.
134 135 136 |
# File 'lib/colorable/color_space.rb', line 134 def h @h end |
#hsb ⇒ Object Also known as: to_a
Returns the value of attribute hsb.
134 135 136 |
# File 'lib/colorable/color_space.rb', line 134 def hsb @hsb end |
#s ⇒ Object Also known as: sat
Returns the value of attribute s.
134 135 136 |
# File 'lib/colorable/color_space.rb', line 134 def s @s end |
Instance Method Details
#+(arg) ⇒ Object
Pass Array of [h, s, b] or a Fixnum. Returns new HSB object with added HSB.
146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/colorable/color_space.rb', line 146 def +(arg) arg = case arg when Array raise ArgumentError, "Must be three numbers contained" unless arg.size==3 arg else raise ArgumentError, "Accept only Array of three numbers" end new_hsb = self.hsb.zip(arg, [360, 101, 101]).map { |x, y, div| (x + y) % div } self.class.new *new_hsb end |
#to_hex ⇒ Object
167 168 169 |
# File 'lib/colorable/color_space.rb', line 167 def to_hex rgb2hex(self.to_rgb) end |
#to_name ⇒ Object
159 160 161 |
# File 'lib/colorable/color_space.rb', line 159 def to_name rgb2name(self.to_rgb) end |
#to_rgb ⇒ Object
163 164 165 |
# File 'lib/colorable/color_space.rb', line 163 def to_rgb hsb2rgb(self.to_a) end |