class Sass::Script::Value::Map

A SassScript object representing a map from keys to values. Both keys and values can be any SassScript object.

Attributes

to_h[R]

The Ruby hash containing the contents of this map.

@return [Hash<Node, Node>]

value[R]

The Ruby hash containing the contents of this map.

@return [Hash<Node, Node>]

Public Class Methods

new(hash) click to toggle source

Creates a new map.

@param hash [Hash<Node, Node>]

Calls superclass method Sass::Script::Value::Base::new
# File lib/sass/script/value/map.rb, line 14
def initialize(hash)
  super(hash)
end

Public Instance Methods

eq(other) click to toggle source

@see Value#eq

# File lib/sass/script/value/map.rb, line 42
def eq(other)
  Bool.new(other.is_a?(Map) && value == other.value)
end
hash() click to toggle source
# File lib/sass/script/value/map.rb, line 46
def hash
  @hash ||= value.hash
end
inspect(opts = {})
Alias for: to_sass
options=(options) click to toggle source

@see Value#options=

Calls superclass method
# File lib/sass/script/value/map.rb, line 19
def options=(options)
  super
  value.each do |k, v|
    k.options = options
    v.options = options
  end
end
separator() click to toggle source

@see Value#separator

# File lib/sass/script/value/map.rb, line 28
def separator
  :comma unless value.empty?
end
to_a() click to toggle source

@see Value#to_a

# File lib/sass/script/value/map.rb, line 33
def to_a
  value.map do |k, v|
    list = List.new([k, v], separator: :space)
    list.options = options
    list
  end
end
to_s(opts = {}) click to toggle source

@see Value#to_s

# File lib/sass/script/value/map.rb, line 51
def to_s(opts = {})
  raise Sass::SyntaxError.new("#{inspect} isn't a valid CSS value.")
end
to_sass(opts = {}) click to toggle source
# File lib/sass/script/value/map.rb, line 55
def to_sass(opts = {})
  return "()" if value.empty?

  to_sass = lambda do |value|
    if value.is_a?(List) && value.separator == :comma
      "(#{value.to_sass(opts)})"
    else
      value.to_sass(opts)
    end
  end

  "(#{value.map {|(k, v)| "#{to_sass[k]}: #{to_sass[v]}"}.join(', ')})"
end
Also aliased as: inspect