Class: WizRtf::Color

Inherits:
Object
  • Object
show all
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'
'#000080'
PURPLE =
'#800080'
WHITE =
'#FFFFFF'
SILVER =
'#C0C0C0'
GRAY =
'#808080'
BLACK =
'#000000'

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#blueObject (readonly)

Returns the value of attribute blue.



26
27
28
# File 'lib/wiz_rtf/color.rb', line 26

def blue
  @blue
end

#greenObject (readonly)

Returns the value of attribute green.



26
27
28
# File 'lib/wiz_rtf/color.rb', line 26

def green
  @green
end

#redObject (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_rgbObject



47
48
49
# File 'lib/wiz_rtf/color.rb', line 47

def to_rgb
  [@red, @green, @blue]
end

#to_rgb_hexObject



51
52
53
# File 'lib/wiz_rtf/color.rb', line 51

def to_rgb_hex
  "#" + to_rgb.map {|c| "%02X" % c }.join
end