Class: Sass::Util::NormalizedMap
- Inherits:
-
Object
- Object
- Sass::Util::NormalizedMap
show all
- Defined in:
- lib/sass/util/normalized_map.rb
Instance Method Summary
collapse
Constructor Details
12
13
14
15
16
17
|
# File 'lib/sass/util/normalized_map.rb', line 12
def initialize(map = nil)
@key_strings = {}
@map = Util.ruby1_8? ? OrderedHash.new : {}
map.each {|key, value| self[key] = value} if map
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block)
112
113
114
115
116
117
|
# File 'lib/sass/util/normalized_map.rb', line 112
def method_missing(method, *args, &block)
if Sass.tests_running
raise ArgumentError.new("The method #{method} must be implemented explicitly")
end
@map.send(method, *args, &block)
end
|
Instance Method Details
#as_stored ⇒ Hash
Returns Hash with the keys as they were stored (before normalization).
61
62
63
|
# File 'lib/sass/util/normalized_map.rb', line 61
def as_stored
Sass::Util.map_keys(@map) {|k| @key_strings[k]}
end
|
#denormalize(key) ⇒ String
Returns the version of key
as it was stored before
normalization. If key
isn't in the map, returns it as it was
passed in.
31
32
33
|
# File 'lib/sass/util/normalized_map.rb', line 31
def denormalize(key)
@key_strings[normalize(key)] || key
end
|
#dup
97
98
99
100
101
|
# File 'lib/sass/util/normalized_map.rb', line 97
def dup
d = super
d.send(:instance_variable_set, "@map", @map.dup)
d
end
|
#each
77
78
79
|
# File 'lib/sass/util/normalized_map.rb', line 77
def each
@map.each {|k, v| yield(k, v)}
end
|
#empty? ⇒ Boolean
65
66
67
|
# File 'lib/sass/util/normalized_map.rb', line 65
def empty?
@map.empty?
end
|
#keys
73
74
75
|
# File 'lib/sass/util/normalized_map.rb', line 73
def keys
@map.keys
end
|
#map
93
94
95
|
# File 'lib/sass/util/normalized_map.rb', line 93
def map
@map.map {|k, v| yield(k, v)}
end
|
#normalize(key)
Specifies how to transform the key.
This can be overridden to create other normalization behaviors.
22
23
24
|
# File 'lib/sass/util/normalized_map.rb', line 22
def normalize(key)
key.tr("-", "_")
end
|
#respond_to?(method, include_private = false) ⇒ Boolean
120
121
122
|
# File 'lib/sass/util/normalized_map.rb', line 120
def respond_to?(method, include_private = false)
super || @map.respond_to?(method, include_private)
end
|
#respond_to_missing?(method, include_private = false) ⇒ Boolean
125
126
127
|
# File 'lib/sass/util/normalized_map.rb', line 125
def respond_to_missing?(method, include_private = false)
@map.respond_to?(method, include_private)
end
|
#size
81
82
83
|
# File 'lib/sass/util/normalized_map.rb', line 81
def size
@map.size
end
|
#sort_by
103
104
105
|
# File 'lib/sass/util/normalized_map.rb', line 103
def sort_by
@map.sort_by {|k, v| yield k, v}
end
|
#to_a
89
90
91
|
# File 'lib/sass/util/normalized_map.rb', line 89
def to_a
@map.to_a
end
|
#to_hash
85
86
87
|
# File 'lib/sass/util/normalized_map.rb', line 85
def to_hash
@map.dup
end
|
#update(map)
107
108
109
110
|
# File 'lib/sass/util/normalized_map.rb', line 107
def update(map)
map = map.as_stored if map.is_a?(NormalizedMap)
map.each {|k, v| self[k] = v}
end
|
#values
69
70
71
|
# File 'lib/sass/util/normalized_map.rb', line 69
def values
@map.values
end
|