Class: Colorable::NAME

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

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

#nameObject 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 (readonly)

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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

Returns:

  • (Boolean)


261
262
263
# File 'lib/colorable/color_space.rb', line 261

def dark?
  DARK_COLORS.detect { |d| d == self.name }
end

#to_hexObject



292
293
294
# File 'lib/colorable/color_space.rb', line 292

def to_hex
  rgb2hex(self.to_rgb)
end

#to_hsbObject



288
289
290
# File 'lib/colorable/color_space.rb', line 288

def to_hsb
  rgb2hsb(self.to_rgb)
end

#to_rgbObject



284
285
286
# File 'lib/colorable/color_space.rb', line 284

def to_rgb
  name2rgb(self.to_s)
end