Class: Colors::NamedColors::Mapping
- Inherits:
-
Object
- Object
- Colors::NamedColors::Mapping
- Defined in:
- lib/colors/named_colors.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #delete(name) ⇒ Object
-
#initialize ⇒ Mapping
constructor
A new instance of Mapping.
- #update(other) ⇒ Object
Constructor Details
permalink #initialize ⇒ Mapping
Returns a new instance of Mapping.
4 5 6 7 |
# File 'lib/colors/named_colors.rb', line 4 def initialize @mapping = {} @cache = {} end |
Instance Method Details
permalink #[](name) ⇒ Object
[View source]
9 10 11 12 13 14 15 |
# File 'lib/colors/named_colors.rb', line 9 def [](name) if NamedColors.nth_color?(name) cycle = ColorData::DEFAULT_COLOR_CYCLE name = cycle[name[1..-1].to_i % cycle.length] end @cache[name] ||= lookup_no_color_cycle(name) end |
permalink #[]=(name, value) ⇒ Object
[View source]
55 56 57 58 59 |
# File 'lib/colors/named_colors.rb', line 55 def []=(name, value) @mapping[name] = value ensure @cache.clear end |
permalink #delete(name) ⇒ Object
[View source]
61 62 63 64 65 |
# File 'lib/colors/named_colors.rb', line 61 def delete(name) @mapping.delete(name) ensure @cache.clear end |
permalink #update(other) ⇒ Object
[View source]
67 68 69 70 71 |
# File 'lib/colors/named_colors.rb', line 67 def update(other) @mapping.update(other) ensure @cache.clear end |