Class: Colour::RGB
Overview
A lightweight implementation of rgb/hex colors, designed for web use.
c = Colour::RGB.new(0xFFFFFF)
c.to_s -> "ffffff"
c.red = 196
c.green = 0xDD
c.blue = 'EE'
c.to_s -> "c4ddee"
Similar to (see also) ColorTools.
Instance Attribute Summary collapse
-
#blue ⇒ Object
readonly
:startdoc:.
-
#green ⇒ Object
readonly
:startdoc:.
-
#red ⇒ Object
readonly
:startdoc:.
Instance Method Summary collapse
-
#initialize(*rgb) ⇒ RGB
constructor
The following are the same colour:.
-
#to_s ⇒ Object
Returns the hexadecimal string representation of the colour e.g.
Constructor Details
#initialize(*rgb) ⇒ RGB
55 56 57 58 59 |
# File 'lib/quality_extensions/color/rgb.rb', line 55 def initialize(*rgb) (rgb.size == 1 ? rgb[0].to_rgb : rgb).zip([:red, :green, :blue]) do |(value, col)| set!(col, value) end end |
Instance Attribute Details
#blue ⇒ Object (readonly)
:startdoc:
46 47 48 |
# File 'lib/quality_extensions/color/rgb.rb', line 46 def blue @blue end |
#green ⇒ Object (readonly)
:startdoc:
46 47 48 |
# File 'lib/quality_extensions/color/rgb.rb', line 46 def green @green end |
#red ⇒ Object (readonly)
:startdoc:
46 47 48 |
# File 'lib/quality_extensions/color/rgb.rb', line 46 def red @red end |
Instance Method Details
#to_s ⇒ Object
Returns the hexadecimal string representation of the colour e.g.
RGB.new(255, 255, 255).to_s -> "FFFFFF"
65 66 67 |
# File 'lib/quality_extensions/color/rgb.rb', line 65 def to_s "%02x%02x%02x" % [ red, green, blue ] end |