Sha256: ea7d6c3d209ec9305dfadf09369d2725c403cd9746eb9f003e30659dfb5e04ce

Contents?: true

Size: 409 Bytes

Versions: 3

Compression:

Stored size: 409 Bytes

Contents

module ColorConversion
  class RgbConverter < ColorConverter

    def self.matches?(color)
      return false unless color.kind_of?(Hash)

      color.include?(:r) && color.include?(:g) && color.include?(:b)
    end
    
    private
    
    def to_rgba(rgb)
      r = rgb[:r].to_f
      g = rgb[:g].to_f
      b = rgb[:b].to_f
      a = (rgb[:a] || 1.0).to_f

      {r: r, g: g, b: b, a: a}
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
color_conversion-0.1.2 lib/color_conversion/converters/rgb_converter.rb
color_conversion-0.1.1 lib/color_conversion/converters/rgb_converter.rb
color_conversion-0.1.0 lib/color_conversion/converters/rgb_converter.rb