Module: Sai::Registry Private

Defined in:
lib/sai/registry.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

The named color registry

Author:

Since:

  • 0.4.0

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Array<Integer>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Look up an RGB value by color name

Parameters:

  • name (String, Symbol) —

    the color name

Returns:

  • (Array<Integer>) —

    the RGB value

Author:

Since:

  • 0.3.1



23
24
25
# File 'lib/sai/registry.rb', line 23

def [](name)
  lookup[name.to_sym]
end

.names ⇒ Array<Symbol>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get a list of all color names

Returns:

  • (Array<Symbol>) —

    the color names

Author:

Since:

  • 0.3.1



35
36
37
# File 'lib/sai/registry.rb', line 35

def names
  @names ||= lookup.keys.uniq.sort
end

.register(name, rgb_or_hex) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Register a named color with an RGB or Hexadecimal value

Parameters:

  • name (String, Symbol) —

    the name of the color being registered

  • rgb_or_hex (Array<Integer>, String) —

    the RGB or Hexadecimal value of the color

Returns:

  • (Boolean) —

    true if the color was registered

Author:

Since:

  • 0.4.0



51
52
53
54
55
56
57
# File 'lib/sai/registry.rb', line 51

def register(name, rgb_or_hex)
  key = name.to_s.downcase.to_sym
  rgb = Conversion::RGB.resolve(rgb_or_hex)
  thread_lock.synchronize { lookup[key] = rgb }
  broadcast_registration(key)
  true
end

.subscribe(subscriber) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Subscribe to registry changes

Parameters:

  • subscriber (Object) —

    the subscriber

Author:

Since:

  • 0.4.0



70
71
72
# File 'lib/sai/registry.rb', line 70

def subscribe(subscriber)
  thread_lock.synchronize { subscribers << subscriber }
end