Class: Colors::NamedColors::Mapping
- Inherits:
-
Object
- Object
- Colors::NamedColors::Mapping
- Defined in:
- lib/colors/named_colors.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
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
#initialize ⇒ Mapping
Returns a new instance of Mapping.
6 7 8 9 |
# File 'lib/colors/named_colors.rb', line 6 def initialize @mapping = {} @cache = {} end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
11 12 13 |
# File 'lib/colors/named_colors.rb', line 11 def cache @cache end |
Instance Method Details
#[](name) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/colors/named_colors.rb', line 13 def [](name) if NamedColors.nth_color?(name) cycle = ColorData::DEFAULT_COLOR_CYCLE name = cycle[name[1..-1].to_i % cycle.length] end if cache.has_key?(name) cache[name] else cache[name] = lookup_no_color_cycle(name) end end |
#[]=(name, value) ⇒ Object
64 65 66 67 68 |
# File 'lib/colors/named_colors.rb', line 64 def []=(name, value) @mapping[name] = value ensure cache.clear end |
#delete(name) ⇒ Object
70 71 72 73 74 |
# File 'lib/colors/named_colors.rb', line 70 def delete(name) @mapping.delete(name) ensure cache.clear end |
#update(other) ⇒ Object
76 77 78 79 80 |
# File 'lib/colors/named_colors.rb', line 76 def update(other) @mapping.update(other) ensure cache.clear end |