Module: ColorMath::Color
Overview
Color can be mixed into any class that responds to red, green, and blue, where 0 <= c <= 1
Instance Method Summary collapse
-
#compact_hex ⇒ Object
The hexadecimal representation of the colour, using 3 digits if possible.
-
#hex ⇒ Object
The six-digit hexadecimal representation of the colour, e.g.
- #inspect(*args) ⇒ Object
Instance Method Details
#compact_hex ⇒ Object
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 |
#hex ⇒ Object
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 |