Class: Color::RGB
Overview
A lightweight implementation of rgb/hex colors, designed for web use.
c = Color::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
- #==(other) ⇒ Object
-
#initialize(*rgb) ⇒ RGB
constructor
The following are the same color:.
- #inspect ⇒ Object
-
#to_i ⇒ Object
Returns the integral representation of the color, f.e.:.
-
#to_s ⇒ Object
Returns the hexadecimal string representation of the color, f.e.:.
Constructor Details
#initialize(*rgb) ⇒ RGB
67 68 69 70 71 |
# File 'lib/quality_extensions/color/rgb.rb', line 67 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:
58 59 60 |
# File 'lib/quality_extensions/color/rgb.rb', line 58 def blue @blue end |
#green ⇒ Object (readonly)
:startdoc:
58 59 60 |
# File 'lib/quality_extensions/color/rgb.rb', line 58 def green @green end |
#red ⇒ Object (readonly)
:startdoc:
58 59 60 |
# File 'lib/quality_extensions/color/rgb.rb', line 58 def red @red end |
Instance Method Details
#==(other) ⇒ Object
93 94 95 |
# File 'lib/quality_extensions/color/rgb.rb', line 93 def ==(other) to_s == other.to_s end |
#inspect ⇒ Object
81 82 83 |
# File 'lib/quality_extensions/color/rgb.rb', line 81 def inspect "<Color::RGB '#{to_s}'>" end |
#to_i ⇒ Object
Returns the integral representation of the color, f.e.:
RGB.new(255, 255, 255).to_i -> "FFFFFF"
89 90 91 |
# File 'lib/quality_extensions/color/rgb.rb', line 89 def to_i red*65536 + green*256 + blue end |
#to_s ⇒ Object
Returns the hexadecimal string representation of the color, f.e.:
RGB.new(255, 255, 255).to_s -> "FFFFFF"
77 78 79 |
# File 'lib/quality_extensions/color/rgb.rb', line 77 def to_s "%02x%02x%02x" % [ red, green, blue ] end |