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 Method Summary collapse
- #from_rgb(*rgb) ⇒ Object
- #from_rgb_hex(color) ⇒ Object
-
#initialize(*rgb) ⇒ Color
constructor
A new instance of Color.
- #render(io) ⇒ Object
- #to_rgb ⇒ Object
- #to_rgb_hex ⇒ Object
Constructor Details
#initialize(*rgb) ⇒ Color
Returns a new instance of Color.
26 27 28 29 30 31 32 33 |
# File 'lib/wiz_rtf/color.rb', line 26 def initialize(*rgb) case rgb.size when 1 from_rgb_hex(rgb.first) when 3 from_rgb(*rgb) end end |
Instance Method Details
#from_rgb(*rgb) ⇒ Object
41 42 43 |
# File 'lib/wiz_rtf/color.rb', line 41 def from_rgb(*rgb) @red, @green, @blue = rgb end |
#from_rgb_hex(color) ⇒ Object
35 36 37 38 39 |
# File 'lib/wiz_rtf/color.rb', line 35 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 |
#render(io) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/wiz_rtf/color.rb', line 53 def render(io) io.delimit do io.cmd :red, @red io.cmd :green, @green io.cmd :blue, @blue end end |
#to_rgb ⇒ Object
45 46 47 |
# File 'lib/wiz_rtf/color.rb', line 45 def to_rgb [@red, @green, @blue] end |
#to_rgb_hex ⇒ Object
49 50 51 |
# File 'lib/wiz_rtf/color.rb', line 49 def to_rgb_hex "#" + to_rgb.map {|c| "%02X" % c }.join end |