Class: Colorable::HEX

Inherits:
ColorSpace show all
Defined in:
lib/colorable/color_space.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ColorSpace

#<=>, #coerce, #move_to_top

Methods included from Converter

#hsb2rgb, #name2rgb, #rgb2hsb, #rgb2hsl, #rgb2name

Constructor Details

#initialize(hex = '#FFFFFF') ⇒ HEX

Returns a new instance of HEX.



179
180
181
# File 'lib/colorable/color_space.rb', line 179

def initialize(hex='#FFFFFF')
  @hex = validate_hex(hex)
end

Instance Attribute Details

#hexObject (readonly) Also known as: to_s

Returns the value of attribute hex.



178
179
180
# File 'lib/colorable/color_space.rb', line 178

def hex
  @hex
end

Instance Method Details

#+(arg) ⇒ Object



188
189
190
# File 'lib/colorable/color_space.rb', line 188

def +(arg)
  build_hex_with(:+, arg)
end

#-(arg) ⇒ Object



192
193
194
# File 'lib/colorable/color_space.rb', line 192

def -(arg)
  build_hex_with(:-, arg)
end

#to_aObject



184
185
186
# File 'lib/colorable/color_space.rb', line 184

def to_a
  @hex.unpack('A1A2A2A2').drop(1)
end

#to_hsbObject



200
201
202
# File 'lib/colorable/color_space.rb', line 200

def to_hsb
  rgb2hsb(self.to_rgb)
end

#to_nameObject



204
205
206
# File 'lib/colorable/color_space.rb', line 204

def to_name
  rgb2name(self.to_rgb)
end

#to_rgbObject



196
197
198
# File 'lib/colorable/color_space.rb', line 196

def to_rgb
  hex2rgb(self.to_s)
end