Sha256: 1a077ec74667221e09a41f1e49202e6ee72561d70d712b20bb4b9424aea69572

Contents?: true

Size: 1.6 KB

Versions: 31

Compression:

Stored size: 1.6 KB

Contents

# -*- coding: utf-8 -*-

module Writeexcel

class Colors
  COLORS = {
    :aqua    => 0x0F,
    :cyan    => 0x0F,
    :black   => 0x08,
    :blue    => 0x0C,
    :brown   => 0x10,
    :magenta => 0x0E,
    :fuchsia => 0x0E,
    :gray    => 0x17,
    :grey    => 0x17,
    :green   => 0x11,
    :lime    => 0x0B,
    :navy    => 0x12,
    :orange  => 0x35,
    :pink    => 0x21,
    :purple  => 0x14,
    :red     => 0x0A,
    :silver  => 0x16,
    :white   => 0x09,
    :yellow  => 0x0D,
  }   # :nodoc:

  ###############################################################################
  #
  # get_color(colour)
  #
  # Used in conjunction with the set_xxx_color methods to convert a color
  # string into a number. Color range is 0..63 but we will restrict it
  # to 8..63 to comply with Gnumeric. Colors 0..7 are repeated in 8..15.
  #
  def get_color(color = nil) # :nodoc:
    if color.respond_to?(:to_int) && color.respond_to?(:+)
      # the default color if arg is outside range,
      if color < 0 || 63 < color
        0x7FFF
      # or an index < 8 mapped into the correct range,
      elsif color < 8
        (color + 8).to_i
      # or an integer in the valid range
      else
        color.to_i
      end
    elsif color.respond_to?(:to_sym)
      color = color.downcase.to_sym if color.respond_to?(:to_str)
      # or the color string converted to an integer,
      if COLORS.has_key?(color)
        COLORS[color]
      # or the default color if string is unrecognised,
      else
        0x7FFF
      end
    else
      0x7FFF
    end
  end

  def inspect
    to_s
  end
end  # class Colors

end  # module Writeexcel

Version data entries

31 entries across 31 versions & 3 rubygems

Version Path
writeexcel-1.0.9 lib/writeexcel/colors.rb
writeexcel-1.0.8 lib/writeexcel/colors.rb
writeexcel-1.0.7 lib/writeexcel/colors.rb
writeexcel-1.0.6 lib/writeexcel/colors.rb
writeexcel-1.0.5 lib/writeexcel/colors.rb
writeexcel-1.0.4 lib/writeexcel/colors.rb
writeexcel-1.0.3 lib/writeexcel/colors.rb
writeexcel-1.0.2 lib/writeexcel/colors.rb
writeexcel-1.0.1 lib/writeexcel/colors.rb
writeexcel-1.0.0 lib/writeexcel/colors.rb
writeexcel-0.6.19 lib/writeexcel/colors.rb
writeexcel-0.6.18 lib/writeexcel/colors.rb
writeexcel-0.6.17 lib/writeexcel/colors.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/writeexcel-0.6.16/lib/writeexcel/colors.rb
writeexcel-0.6.16 lib/writeexcel/colors.rb
writeexcel-0.6.15 lib/writeexcel/colors.rb
writeexcel-0.6.14 lib/writeexcel/colors.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/writeexcel-0.6.13/lib/writeexcel/colors.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/writeexcel-0.6.13/lib/writeexcel/colors.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/writeexcel-0.6.13/lib/writeexcel/colors.rb