Class: Sass::Value::Map

Inherits:
Object
  • Object
show all
Includes:
Sass::Value
Defined in:
lib/sass/value/map.rb

Overview

Sass’s map type.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Sass::Value

#[], #assert_boolean, #assert_calculation, #assert_color, #assert_function, #assert_number, #assert_string, #bracketed?, #eql?, #sass_index_to_array_index, #to_bool, #to_nil

Constructor Details

#initialize(contents = {}) ⇒ Map

Returns a new instance of Map.

Parameters:



12
13
14
# File 'lib/sass/value/map.rb', line 12

def initialize(contents = {})
  @contents = contents.freeze
end

Instance Attribute Details

#contentsHash<Value, Value> (readonly)

Returns:



17
18
19
# File 'lib/sass/value/map.rb', line 17

def contents
  @contents
end

Instance Method Details

#==(other) ⇒ ::Boolean

Returns:

  • (::Boolean)


25
26
27
28
# File 'lib/sass/value/map.rb', line 25

def ==(other)
  (other.is_a?(Sass::Value::Map) && other.contents == contents) ||
    (contents.empty? && other.is_a?(Sass::Value::List) && other.to_a.empty?)
end

#assert_map(_name = nil) ⇒ Map

Returns:



60
61
62
# File 'lib/sass/value/map.rb', line 60

def assert_map(_name = nil)
  self
end

#at(index) ⇒ List<(Value, Value)>, Value

Parameters:

Returns:



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/sass/value/map.rb', line 32

def at(index)
  if index.is_a? Numeric
    index = index.floor
    index = to_a_length + index if index.negative?
    return nil if index.negative? || index >= to_a_length

    Sass::Value::List.new(contents.to_a[index], separator: ' ')
  else
    contents[index]
  end
end

#hashInteger

Returns:

  • (Integer)


45
46
47
# File 'lib/sass/value/map.rb', line 45

def hash
  @hash ||= contents.hash
end

#separator::String?

Returns:

  • (::String, nil)


20
21
22
# File 'lib/sass/value/map.rb', line 20

def separator
  contents.empty? ? nil : ','
end

#to_aArray<List<(Value, Value)>>

Returns:



50
51
52
# File 'lib/sass/value/map.rb', line 50

def to_a
  contents.map { |key, value| Sass::Value::List.new([key, value], separator: ' ') }
end

#to_mapMap

Returns:



55
56
57
# File 'lib/sass/value/map.rb', line 55

def to_map
  self
end