Class: Abachrome::ColorSpace

Inherits:
Object
  • Object
show all
Defined in:
lib/abachrome/color_space.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) {|self| ... } ⇒ Abachrome::ColorSpace

Initialize a new ColorSpace instance.

Parameters:

  • name (String, Symbol)

    The name of the color space, which will be converted to a symbol

Yields:

  • (self)

    Yields self to the block for configuration if a block is given



67
68
69
70
# File 'lib/abachrome/color_space.rb', line 67

def initialize(name)
  @name = name.to_sym
  yield self if block_given?
end

Instance Attribute Details

#color_modelObject

Returns the value of attribute color_model.



60
61
62
# File 'lib/abachrome/color_space.rb', line 60

def color_model
  @color_model
end

#coordinatesObject

Returns the value of attribute coordinates.



60
61
62
# File 'lib/abachrome/color_space.rb', line 60

def coordinates
  @coordinates
end

#nameObject (readonly)

Returns the value of attribute name.



60
61
62
# File 'lib/abachrome/color_space.rb', line 60

def name
  @name
end

#white_pointObject

Returns the value of attribute white_point.



60
61
62
# File 'lib/abachrome/color_space.rb', line 60

def white_point
  @white_point
end

Class Method Details

.alias(name, aliased_name) ⇒ void

This method returns an undefined value.

Aliases a color space name to an existing registered color space.

This method creates an alias for an existing color space in the registry, allowing the same color space to be accessed through multiple names.

Parameters:

  • name (Symbol, String)

    The existing color space name already registered

  • aliased_name (Symbol, String)

    The new alias name to register



48
49
50
# File 'lib/abachrome/color_space.rb', line 48

def alias(name, aliased_name)
  registry[aliased_name.to_sym] = registry[name.to_sym]
end

.find(name) ⇒ Abachrome::ColorSpace

Returns The color space with the given name.

Parameters:

  • name (String, Symbol)

    The name of the color space to find

Returns:

Raises:

  • (ArgumentError)

    If no color space with the given name exists in the registry



55
56
57
# File 'lib/abachrome/color_space.rb', line 55

def find(name)
  registry[name.to_sym] or raise ArgumentError, "Unknown color space: #{name}"
end

.register(name, &block) ⇒ Abachrome::ColorSpace

Registers a new color space with the specified name.

Parameters:

  • name (String, Symbol)

    The identifier for the color space

  • block (Proc)

    A block that configures the color space properties

Returns:



36
37
38
# File 'lib/abachrome/color_space.rb', line 36

def register(name, &block)
  registry[name.to_sym] = new(name, &block)
end

.registryHash

A registry of all registered color spaces.

Returns:

  • (Hash)

    A memoized hash where keys are color space identifiers and values are the corresponding color space objects



27
28
29
# File 'lib/abachrome/color_space.rb', line 27

def registry
  @registry ||= {}
end

Instance Method Details

#==(other) ⇒ Boolean

Compares this ColorSpace instance with another to check for equality.

Two ColorSpace objects are considered equal if they have the same name.

Parameters:

  • other (Object)

    The object to compare against

Returns:

  • (Boolean)

    true if other is a ColorSpace with the same name, false otherwise



106
107
108
109
110
# File 'lib/abachrome/color_space.rb', line 106

def ==(other)
  return false unless other.is_a?(ColorSpace)

  name == other.name
end

#eql?(other) ⇒ Boolean

Checks if two color spaces are equal.

Parameters:

Returns:

  • (Boolean)

    true if the color spaces are equal, false otherwise



116
117
118
# File 'lib/abachrome/color_space.rb', line 116

def eql?(other)
  self == other
end

#hashInteger

Returns a hash value for the color space based on its name.

used for equality comparison and as a hash key.

Returns:

  • (Integer)

    A hash value computed from the color space name that can be



124
125
126
# File 'lib/abachrome/color_space.rb', line 124

def hash
  name.hash
end

#idString, Symbol

Returns the identifier for the color space, which is currently the same as its name.

Returns:

  • (String, Symbol)

    the identifier of the color space



130
131
132
# File 'lib/abachrome/color_space.rb', line 130

def id
  name
end