Class: Colorable::NAME
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from ColorSpace
#move_to_top
Methods included from Converter
#hex2rgb, #hsb2rgb, #name2rgb, #rgb2hex, #rgb2hsb, #rgb2hsl, #rgb2name
Constructor Details
#initialize(name) ⇒ NAME
Returns a new instance of NAME.
250
251
252
253
|
# File 'lib/colorable/color_space.rb', line 250
def initialize(name)
@name = find_name(name)
@sym = nil
end
|
Instance Attribute Details
#name ⇒ Object
Also known as:
to_s
Returns the value of attribute name.
248
249
250
|
# File 'lib/colorable/color_space.rb', line 248
def name
@name
end
|
#sym(sep = '_') ⇒ Object
Returns the value of attribute sym.
249
250
251
|
# File 'lib/colorable/color_space.rb', line 249
def sym
@sym
end
|
Instance Method Details
#+(n) ⇒ Object
269
270
271
272
273
|
# File 'lib/colorable/color_space.rb', line 269
def +(n)
raise ArgumentError, 'Only accept a Fixnum' unless n.is_a?(Fixnum)
pos = COLORNAMES.find_index{|n,_| n==self.name} + n
self.class.new COLORNAMES.at(pos % COLORNAMES.size)[0]
end
|
#-(n) ⇒ Object
275
276
277
278
|
# File 'lib/colorable/color_space.rb', line 275
def -(n)
raise ArgumentError, 'Only accept a Fixnum' unless n.is_a?(Fixnum)
self + -n
end
|
#<=>(other) ⇒ Object
265
266
267
|
# File 'lib/colorable/color_space.rb', line 265
def <=>(other)
self.name <=> other.name
end
|
#coerce(arg) ⇒ Object
280
281
282
|
# File 'lib/colorable/color_space.rb', line 280
def coerce(arg)
[self, arg]
end
|
#dark? ⇒ Boolean
261
262
263
|
# File 'lib/colorable/color_space.rb', line 261
def dark?
DARK_COLORS.detect { |d| d == self.name }
end
|
#to_hex ⇒ Object
292
293
294
|
# File 'lib/colorable/color_space.rb', line 292
def to_hex
rgb2hex(self.to_rgb)
end
|
#to_hsb ⇒ Object
288
289
290
|
# File 'lib/colorable/color_space.rb', line 288
def to_hsb
rgb2hsb(self.to_rgb)
end
|
#to_rgb ⇒ Object
284
285
286
|
# File 'lib/colorable/color_space.rb', line 284
def to_rgb
name2rgb(self.to_s)
end
|