Class: Colors::NamedColors::Mapping

Inherits:
Object
  • Object
show all
Defined in:
lib/colors/named_colors.rb

Instance Method Summary collapse

Constructor Details

#initializeMapping

Returns a new instance of Mapping.

[View source]

4
5
6
7
# File 'lib/colors/named_colors.rb', line 4

def initialize
  @mapping = {}
  @cache = {}
end

Instance Method Details

#[](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

#[]=(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

#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

#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