Sha256: a2a3ec018579d5bec8a7ec253c656b02534cb8d0472bff33dd5cf233e1846fce

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

# encoding: utf-8

# WizRft:  A gem for exporting Word Documents in ruby
# using the Microsoft Rich Text Format (RTF) Specification
# Copyright (C) 2015 by sgzhe@163.com

module WizRtf
  class Color
    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'

    attr_reader :red, :green, :blue

    def initialize(*rgb)
      case rgb.size
        when 1
          from_rgb_hex(rgb.first)
        when 3
          from_rgb(*rgb)
      end
    end

    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

    def from_rgb(*rgb)
      @red, @green, @blue = rgb
    end

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

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

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wiz_rtf-0.6.9 lib/wiz_rtf/color.rb
wiz_rtf-0.6.8 lib/wiz_rtf/color.rb