Sha256: 86bbce04060753ae030518a24f8b77abec8851f2e9a80165dfefa840eff14947

Contents?: true

Size: 450 Bytes

Versions: 2

Compression:

Stored size: 450 Bytes

Contents

module RGBUtils
  class RGBToHexConverter < Converter
    def initialize(color)
      @color = color
    end

    def convert
      WebSafeToHexConverter.convert(hex_color)
    end

    private

    attr_reader :color

    def hex_color
      @hex_color ||= begin
        return color unless color.is_a?(RGB)

        [color.red, color.green, color.blue].map do |color_node|
          '%02x' % color_node
        end.join
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rgb_utils-0.1.2 lib/rgb_utils/converters/rgb_to_hex_converter.rb
rgb_utils-0.1.1 lib/rgb_utils/converters/rgb_to_hex_converter.rb