Sha256: 429722f0c4a2fa44954eddee9141f1add52791c619c439c11239e232e4df023c

Contents?: true

Size: 848 Bytes

Versions: 1

Compression:

Stored size: 848 Bytes

Contents

# frozen_string_literal: true

module TNS
  # Represents a palette based on a color
  class Palette
    include Enumerable

    def initialize(color)
      @color = color
    end

    def tints
      (1..4).each_with_object([]) do |index, object|
        object << @color.tint(index)
      end.reverse
    end

    def shades
      (1..4).each_with_object([]) do |index, object|
        object << @color.shade(index)
      end
    end

    def to(format)
      case format
      when "hex"
        map(&:to_hex)
      when "hsl"
        map(&:to_hsl)
      when "rgb"
        palette
      else
        raise ArgumentError, "Invalid color format #{format}. Specify hex, hsl or rgb."
      end
    end

    def each(&)
      palette.each(&)
    end

    private

    def palette
      tints + [Color::Tint.new(@color, 0)] + shades
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tints-n-shades-0.1.0 lib/tns/palette.rb