Class: Sass::Script::Value::Map

Inherits:
Base
  • Object
show all
Defined in:
/home/nweiz/code/sass-site/.sass/lib/sass/script/value/map.rb

Overview

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

Instance Attribute Summary (collapse)

Attributes inherited from Base

#options, #source_range

Instance Method Summary (collapse)

Methods inherited from Base

#==, #_perform, #assert_int!, #bracketed, #div, #eql?, #minus, #neq, #null?, #plus, #single_eq, #to_bool, #to_i, #unary_div, #unary_minus, #unary_not, #unary_plus, #with_contents

Constructor Details

- (Map) initialize(hash)

Creates a new map.

Parameters:

  • hash (Hash<Node, Node>)


14
15
16
# File '/home/nweiz/code/sass-site/.sass/lib/sass/script/value/map.rb', line 14

def initialize(hash)
  super(hash)
end

Instance Attribute Details

- (Hash<Node, Node>) value (readonly) Also known as: to_h

The Ruby hash containing the contents of this map.

Returns:

  • (Hash<Node, Node>)


8
9
10
# File '/home/nweiz/code/sass-site/.sass/lib/sass/script/value/map.rb', line 8

def value
  @value
end

Instance Method Details

- eq(other)

See Also:

  • Value#eq


42
43
44
# File '/home/nweiz/code/sass-site/.sass/lib/sass/script/value/map.rb', line 42

def eq(other)
  Bool.new(other.is_a?(Map) && value == other.value)
end

- hash



46
47
48
# File '/home/nweiz/code/sass-site/.sass/lib/sass/script/value/map.rb', line 46

def hash
  @hash ||= value.hash
end

- options=(options)

See Also:

  • Value#options=


19
20
21
22
23
24
25
# File '/home/nweiz/code/sass-site/.sass/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

See Also:

  • Value#separator


28
29
30
# File '/home/nweiz/code/sass-site/.sass/lib/sass/script/value/map.rb', line 28

def separator
  :comma unless value.empty?
end

- to_a

See Also:

  • Value#to_a


33
34
35
36
37
38
39
# File '/home/nweiz/code/sass-site/.sass/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 = {})

Raises:

See Also:

  • Value#to_s


51
52
53
# File '/home/nweiz/code/sass-site/.sass/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 = {}) Also known as: inspect



55
56
57
58
59
60
61
62
63
64
65
66
67
# File '/home/nweiz/code/sass-site/.sass/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