Sha256: d61a6366f7c936b0ea567edfc4ecaf885192c66618525ffa477adf10cba783e5

Contents?: true

Size: 651 Bytes

Versions: 1

Compression:

Stored size: 651 Bytes

Contents

require "hex_to_rgba/version"

module HexToRgba
  class Converter
    attr_accessor :color, :opacity

    def self.convert color, opacity
      if (/([a-fA-F]|[0-9]){3,6}/ =~ color).nil?
        'Wrong color format'
      else
        if color.length == 3
          red = (color[0]*2).to_i 16
          green = (color[1]*2).to_i 16
          blue = (color[2]*2).to_i 16
        elsif color.length == 6
          red = color[0..1].to_i 16
          green = color[3..4].to_i 16
          blue = color[5..6].to_i 16
        else
          'Wrong color format'
        end
        "rgba(#{red}, #{green}, #{blue}, #{opacity})"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hex_to_rgba-0.0.1 lib/hex_to_rgba.rb