Class: SassC::Script::Value::Map
Instance Attribute Summary collapse
#options, #source_range
Instance Method Summary
collapse
#==, #assert_int!, #bracketed, #eql?, #null?, #to_bool, #to_i, #with_contents
Constructor Details
#initialize(hash) ⇒ Map
13
14
15
|
# File 'lib/sassc/script/value/map.rb', line 13
def initialize(hash)
super(hash)
end
|
Instance Attribute Details
#value ⇒ Hash<Node, Node>
Also known as:
to_h
The Ruby hash containing the contents of this map.
7
8
9
|
# File 'lib/sassc/script/value/map.rb', line 7
def value
@value
end
|
Instance Method Details
#eq(other) ⇒ Object
41
42
43
|
# File 'lib/sassc/script/value/map.rb', line 41
def eq(other)
SassC::Script::Value::Bool.new(other.is_a?(Map) && value == other.value)
end
|
#hash ⇒ Object
45
46
47
|
# File 'lib/sassc/script/value/map.rb', line 45
def hash
@hash ||= value.hash
end
|
#options=(options) ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/sassc/script/value/map.rb', line 18
def options=(options)
super
value.each do |k, v|
k.options = options
v.options = options
end
end
|
#separator ⇒ Object
27
28
29
|
# File 'lib/sassc/script/value/map.rb', line 27
def separator
:comma unless value.empty?
end
|
#to_a ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/sassc/script/value/map.rb', line 32
def to_a
value.map do |k, v|
list = SassC::Script::Value::List.new([k, v], separator: :space)
list.options = options
list
end
end
|
#to_s(opts = {}) ⇒ Object
50
51
52
|
# File 'lib/sassc/script/value/map.rb', line 50
def to_s(opts = {})
raise SassC::SyntaxError.new("#{inspect} isn't a valid CSS value.")
end
|
#to_sass(opts = {}) ⇒ Object
Also known as:
inspect
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/sassc/script/value/map.rb', line 54
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
|