Module: ColorMath::Color

Included in:
HSL, RGB
Defined in:
lib/colormath/color.rb

Overview

Color can be mixed into any class that responds to red, green, and blue, where 0 <= c <= 1

Instance Method Summary collapse

Instance Method Details

#compact_hexObject

The hexadecimal representation of the colour, using 3 digits if possible



15
16
17
18
19
20
21
22
# File 'lib/colormath/color.rb', line 15

def compact_hex
  case h = hex
  when /^#(.)\1(.)\2(.)\3$/
    "##$1#$2#$3"
  else
    h
  end
end

#hexObject

The six-digit hexadecimal representation of the colour, e.g. “#cafe66”



9
10
11
# File 'lib/colormath/color.rb', line 9

def hex
  "#%02x%02x%02x" % [red * 0xff, green * 0xff, blue * 0xff]
end

#inspect(*args) ⇒ Object



24
25
26
# File 'lib/colormath/color.rb', line 24

def inspect(*args)
  "<%s r=%0.3f g=%0.3f b=%0.3f>" % [self.class.to_s, red, green, blue]
end