Class: Sass::Util::NormalizedMap

Inherits:
Object
  • Object
show all
Defined in:
/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/util/normalized_map.rb

Instance Method Summary (collapse)

Constructor Details

- (NormalizedMap) initialize(map = nil)

Create a normalized map



11
12
13
14
15
16
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/util/normalized_map.rb', line 11

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)



111
112
113
114
115
116
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/util/normalized_map.rb', line 111

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

- (Hash) as_stored

Returns Hash with the keys as they were stored (before normalization).

Returns:

  • (Hash)

    Hash with the keys as they were stored (before normalization).



60
61
62
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/util/normalized_map.rb', line 60

def as_stored
  Sass::Util.map_keys(@map) {|k| @key_strings[k]}
end

- (String) denormalize(key)

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.

Returns:

  • (String)


30
31
32
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/util/normalized_map.rb', line 30

def denormalize(key)
  @key_strings[normalize(key)] || key
end

- dup



96
97
98
99
100
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/util/normalized_map.rb', line 96

def dup
  d = super
  d.send(:instance_variable_set, "@map", @map.dup)
  d
end

- each



76
77
78
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/util/normalized_map.rb', line 76

def each
  @map.each {|k, v| yield(k, v)}
end

- (Boolean) empty?

Returns:

  • (Boolean)


64
65
66
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/util/normalized_map.rb', line 64

def empty?
  @map.empty?
end

- keys



72
73
74
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/util/normalized_map.rb', line 72

def keys
  @map.keys
end

- map



92
93
94
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/util/normalized_map.rb', line 92

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.



21
22
23
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/util/normalized_map.rb', line 21

def normalize(key)
  key.tr("-", "_")
end

- (Boolean) respond_to?(method, include_private = false)

Returns:

  • (Boolean)


119
120
121
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/util/normalized_map.rb', line 119

def respond_to?(method, include_private = false)
  super || @map.respond_to?(method, include_private)
end

- (Boolean) respond_to_missing?(method, include_private = false)

Returns:

  • (Boolean)


124
125
126
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/util/normalized_map.rb', line 124

def respond_to_missing?(method, include_private = false)
  @map.respond_to?(method, include_private)
end

- size



80
81
82
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/util/normalized_map.rb', line 80

def size
  @map.size
end

- sort_by



102
103
104
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/util/normalized_map.rb', line 102

def sort_by
  @map.sort_by {|k, v| yield k, v}
end

- to_a



88
89
90
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/util/normalized_map.rb', line 88

def to_a
  @map.to_a
end

- to_hash



84
85
86
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/util/normalized_map.rb', line 84

def to_hash
  @map.dup
end

- update(map)



106
107
108
109
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/util/normalized_map.rb', line 106

def update(map)
  map = map.as_stored if map.is_a?(NormalizedMap)
  map.each {|k, v| self[k] = v}
end

- values



68
69
70
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/util/normalized_map.rb', line 68

def values
  @map.values
end