Sha256: c9ac1e7caf028878bc602b76715fa4bdd7ac0f24125085d940fbf441031b094e

Contents?: true

Size: 786 Bytes

Versions: 3

Compression:

Stored size: 786 Bytes

Contents

module Colors
  class AbstractColor
    def desaturate(factor)
      unsupported __method__
    end

    def inspect
      "#{self.class.name}(#{components.join(", ")})"
    end

    private def unsupported(name)
      raise NotImplementedError, "#{name} is unsupported in #{self.class}", caller(2)
    end

    private def canonicalize_component(value, name)
      case value
      when Integer
        canonicalize_component_from_integer(value, name)
      else
        canonicalize_component_to_rational(value, name)
      end
    end

    private def canonicalize_component_from_integer(value, name)
      check_range(value, 0..255, name)/255r
    end

    private def canonicalize_component_to_rational(value, name)
      Rational(check_range(value, 0..1, name))
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
red-colors-0.4.0 lib/colors/abstract_color.rb
red-colors-0.3.0 lib/colors/abstract_color.rb
red-colors-0.2.0 lib/colors/abstract_color.rb