Class: WizRtf::Color
- Inherits:
-
Object
- Object
- WizRtf::Color
- Defined in:
- lib/wiz_rtf/color.rb
Constant Summary collapse
- RED =
'#FF0000'- YELLOW =
'#FFFF00'- LIME =
'#00FF00'- CYAN =
'#00FFFF'- BLUE =
'#0000FF'- MAGENTA =
'#FF00FF'- MAROON =
'#800000'- OLIVE =
'#808000'- GREEN =
'#008000'- TEAL =
'#008080'- NAVY =
'#000080'- PURPLE =
'#800080'- WHITE =
'#FFFFFF'- SILVER =
'#C0C0C0'- GRAY =
'#808080'- BLACK =
'#000000'
Instance Attribute Summary collapse
-
#blue ⇒ Object
readonly
Returns the value of attribute blue.
-
#green ⇒ Object
readonly
Returns the value of attribute green.
-
#red ⇒ Object
readonly
Returns the value of attribute red.
Instance Method Summary collapse
- #from_rgb(*rgb) ⇒ Object
- #from_rgb_hex(color) ⇒ Object
-
#initialize(*rgb) ⇒ Color
constructor
A new instance of Color.
- #to_rgb ⇒ Object
- #to_rgb_hex ⇒ Object
Constructor Details
#initialize(*rgb) ⇒ Color
Returns a new instance of Color.
28 29 30 31 32 33 34 35 |
# File 'lib/wiz_rtf/color.rb', line 28 def initialize(*rgb) case rgb.size when 1 from_rgb_hex(rgb.first) when 3 from_rgb(*rgb) end end |
Instance Attribute Details
#blue ⇒ Object (readonly)
Returns the value of attribute blue.
26 27 28 |
# File 'lib/wiz_rtf/color.rb', line 26 def blue @blue end |
#green ⇒ Object (readonly)
Returns the value of attribute green.
26 27 28 |
# File 'lib/wiz_rtf/color.rb', line 26 def green @green end |
#red ⇒ Object (readonly)
Returns the value of attribute red.
26 27 28 |
# File 'lib/wiz_rtf/color.rb', line 26 def red @red end |
Instance Method Details
#from_rgb(*rgb) ⇒ Object
43 44 45 |
# File 'lib/wiz_rtf/color.rb', line 43 def from_rgb(*rgb) @red, @green, @blue = rgb end |
#from_rgb_hex(color) ⇒ Object
37 38 39 40 41 |
# File 'lib/wiz_rtf/color.rb', line 37 def from_rgb_hex(color) color = '#%.6x' % color if color.is_a? Integer rgb = color[1,7].scan(/.{2}/).map{ |c| c.to_i(16) } from_rgb(*rgb) end |
#to_rgb ⇒ Object
47 48 49 |
# File 'lib/wiz_rtf/color.rb', line 47 def to_rgb [@red, @green, @blue] end |
#to_rgb_hex ⇒ Object
51 52 53 |
# File 'lib/wiz_rtf/color.rb', line 51 def to_rgb_hex "#" + to_rgb.map {|c| "%02X" % c }.join end |