Class: Unmagic::Color::RGB::Named::Database Private
- Inherits:
-
Object
- Object
- Unmagic::Color::RGB::Named::Database
- Defined in:
- lib/unmagic/color/rgb/named.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Database for loading and accessing color data from files.
Handles lazy loading, name normalization, and color lookup.
Instance Attribute Summary collapse
-
#aliases ⇒ Array<String>
readonly
private
Alternative names for the database.
-
#name ⇒ String?
readonly
private
The name of the database.
Instance Method Summary collapse
-
#[](color_name) ⇒ RGB?
private
Lookup color by name, returns RGB color or nil.
-
#all ⇒ Array<String>
private
Get all color names in database.
-
#initialize(path:, name: nil, aliases: []) ⇒ Database
constructor
private
Initialize a new color database.
-
#loaded? ⇒ Boolean
private
Check if database has been loaded.
-
#memsize ⇒ Integer
private
Calculate memory size of loaded database.
-
#valid?(color_name) ⇒ Boolean
private
Check if color exists in database.
Constructor Details
#initialize(path:, name: nil, aliases: []) ⇒ Database
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.
Initialize a new color database.
56 57 58 59 60 61 |
# File 'lib/unmagic/color/rgb/named.rb', line 56 def initialize(path:, name: nil, aliases: []) @filepath = path @name = name @aliases = aliases @data = nil end |
Instance Attribute Details
#aliases ⇒ Array<String> (readonly)
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.
Returns Alternative names for the database.
49 50 51 |
# File 'lib/unmagic/color/rgb/named.rb', line 49 def aliases @aliases end |
#name ⇒ String? (readonly)
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.
Returns The name of the database.
45 46 47 |
# File 'lib/unmagic/color/rgb/named.rb', line 45 def name @name end |
Instance Method Details
#[](color_name) ⇒ RGB?
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.
Lookup color by name, returns RGB color or nil.
67 68 69 70 71 |
# File 'lib/unmagic/color/rgb/named.rb', line 67 def [](color_name) normalized = normalize_name(color_name) int_value = data[normalized] int_value ? RGB.build(int_value) : nil end |
#all ⇒ Array<String>
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 all color names in database.
85 86 87 |
# File 'lib/unmagic/color/rgb/named.rb', line 85 def all data.keys end |
#loaded? ⇒ 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.
Check if database has been loaded.
92 93 94 |
# File 'lib/unmagic/color/rgb/named.rb', line 92 def loaded? !@data.nil? end |
#memsize ⇒ 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.
Calculate memory size of loaded database.
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/unmagic/color/rgb/named.rb', line 100 def memsize require "objspace" memory = ObjectSpace.memsize_of(data) data.each do |key, value| memory += ObjectSpace.memsize_of(key) memory += ObjectSpace.memsize_of(value) end memory end |
#valid?(color_name) ⇒ 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.
Check if color exists in database.
77 78 79 80 |
# File 'lib/unmagic/color/rgb/named.rb', line 77 def valid?(color_name) normalized = normalize_name(color_name) data.key?(normalized) end |