Sha256: c4c51c0331ef60c5e0dcd42bda27f0dacb68b5c7e36b89583fff3fd63f30b529

Contents?: true

Size: 914 Bytes

Versions: 2

Compression:

Stored size: 914 Bytes

Contents

module Joybox
  module Common

    class Color < Array

      def self.defaults
        {
          red: 255,
          green: 255,
          blue: 255
        }
      end

      def initialize(red, green, blue)
        self.push(red, green, blue)
      end

      def self.create(options = {})
        options = options.nil? ? defaults : defaults.merge!(options)
        self.new(options[:red], options[:green], options[:blue])
      end

      def self.from_rgb(red, green, blue)
        self.new(red, green, blue)
      end

      def self.from_hex(hex)
        split_hex = [hex.delete(' ').delete('#')].pack('H*').unpack('C*')

        red = split_hex[0]
        green = split_hex[1]
        blue = split_hex[2]
        
        self.new(red, green, blue)
      end

      def red
        self[0]
      end

      def green
        self[1]
      end

      def blue
        self[2]
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
joybox-1.1.1 motion/joybox/common/color.rb
joybox-1.1.0 motion/joybox/common/color.rb