class Sass::Util::NormalizedMap

Public Class Methods

new(map = nil) click to toggle source

Create a normalized map

# 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

Public Instance Methods

[](k) click to toggle source

@private

# File lib/sass/util/normalized_map.rb, line 44
def [](k)
  @map[normalize(k)]
end
[]=(k, v) click to toggle source

@private

# File lib/sass/util/normalized_map.rb, line 36
def []=(k, v)
  normalized = normalize(k)
  @map[normalized] = v
  @key_strings[normalized] = k
  v
end
as_stored() click to toggle source

@return [Hash] Hash with the keys as they were stored (before normalization).

# File lib/sass/util/normalized_map.rb, line 61
def as_stored
  Sass::Util.map_keys(@map) {|k| @key_strings[k]}
end
delete(k) click to toggle source

@private

# File lib/sass/util/normalized_map.rb, line 54
def delete(k)
  normalized = normalize(k)
  @key_strings.delete(normalized)
  @map.delete(normalized)
end
denormalize(key) click to toggle source

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.

@return [String]

# File lib/sass/util/normalized_map.rb, line 31
def denormalize(key)
  @key_strings[normalize(key)] || key
end
dup() click to toggle source
Calls superclass method
# File lib/sass/util/normalized_map.rb, line 97
def dup
  d = super
  d.send(:instance_variable_set, "@map", @map.dup)
  d
end
each() { |k, v| ... } click to toggle source
# File lib/sass/util/normalized_map.rb, line 77
def each
  @map.each {|k, v| yield(k, v)}
end
empty?() click to toggle source
# File lib/sass/util/normalized_map.rb, line 65
def empty?
  @map.empty?
end
has_key?(k) click to toggle source

@private

# File lib/sass/util/normalized_map.rb, line 49
def has_key?(k)
  @map.has_key?(normalize(k))
end
keys() click to toggle source
# File lib/sass/util/normalized_map.rb, line 73
def keys
  @map.keys
end
map() { |k, v| ... } click to toggle source
# File lib/sass/util/normalized_map.rb, line 93
def map
  @map.map {|k, v| yield(k, v)}
end
method_missing(method, *args, &block) click to toggle source
# 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
normalize(key) click to toggle source

Specifies how to transform the key.

This can be overridden to create other normalization behaviors.

# File lib/sass/util/normalized_map.rb, line 22
def normalize(key)
  key.tr("-", "_")
end
respond_to?(method, include_private = false) click to toggle source
Calls superclass method
# 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) click to toggle source
# 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() click to toggle source
# File lib/sass/util/normalized_map.rb, line 81
def size
  @map.size
end
sort_by() { |k, v| ... } click to toggle source
# File lib/sass/util/normalized_map.rb, line 103
def sort_by
  @map.sort_by {|k, v| yield k, v}
end
to_a() click to toggle source
# File lib/sass/util/normalized_map.rb, line 89
def to_a
  @map.to_a
end
to_hash() click to toggle source
# File lib/sass/util/normalized_map.rb, line 85
def to_hash
  @map.dup
end
update(map) click to toggle source
# 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() click to toggle source
# File lib/sass/util/normalized_map.rb, line 69
def values
  @map.values
end