module SimpleColor::RGB::ColorNames

Public Instance Methods

all_color_names() click to toggle source
# File lib/simplecolor/rgb_colors.rb, line 64
def all_color_names
        return @rgb_color_names if defined? @rgb_color_names
        # A list of color names, based on X11's rgb.txt
        rgb_colors = File.dirname(__FILE__) + "/../../data/rgb_colors.json.gz"
        # Rewrite file:
        # h={}; rgb.each do |k,v| h[SimpleColor::RGB.rgb_clean(k)]=v end
        # Pathname.new("data/rgb_colors.json").write(h.to_json)
        File.open(rgb_colors, "rb") do |file|
                serialized_data = Zlib::GzipReader.new(file).read
                # serialized_data.force_encoding Encoding::BINARY
                @rgb_color_names = JSON.parse(serialized_data)
        end
end
color_names() click to toggle source
# File lib/simplecolor/rgb_colors.rb, line 60
def color_names
        @color_names ||= COLOR_NAMES.dup
end
color_names_priority() click to toggle source
# File lib/simplecolor/rgb_colors.rb, line 78
def color_names_priority
        @rgb_color_names.keys
end
find_color(name) click to toggle source
# File lib/simplecolor/rgb_colors.rb, line 86
def find_color(name)
        custom=color_names
        case name
        when String
                return custom[name] if custom.key?(name)
                name=rgb_clean(name)
                return custom[name] if custom.key?(name)
                colors=all_color_names
                base, rest=name.split(':', 2)
                if rest.nil?
                        color_names_priority.each do |base|
                                c=colors[base]
                                return c[name] if c.key?(name)
                        end
                else
                        c=colors[base]
                        return c[rest] if c
                end
        else
                custom[name]
        end
end
rgb_clean(name) click to toggle source
# File lib/simplecolor/rgb_colors.rb, line 82
def rgb_clean(name) #clean up name
        name.gsub(/\s+/,'').downcase.gsub('gray','grey')
end