Class: Sass::Value::List
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
#[], #assert_boolean, #assert_calculation, #assert_color, #assert_function, #assert_mixin, #assert_number, #assert_string, #eql?, #sass_index_to_array_index, #to_bool, #to_nil
Constructor Details
#initialize(contents = [], separator: ',', bracketed: false) ⇒ List
Returns a new instance of List.
14
15
16
17
18
19
20
21
22
|
# File 'lib/sass/value/list.rb', line 14
def initialize(contents = [], separator: ',', bracketed: false)
if separator.nil? && contents.length > 1
raise Sass::ScriptError, 'A list with more than one element must have an explicit separator'
end
@contents = contents.freeze
@separator = separator.freeze
@bracketed = bracketed.freeze
end
|
Instance Attribute Details
#separator ⇒ ::String?
25
26
27
|
# File 'lib/sass/value/list.rb', line 25
def separator
@separator
end
|
Instance Method Details
#==(other) ⇒ ::Boolean
33
34
35
36
37
38
39
|
# File 'lib/sass/value/list.rb', line 33
def ==(other)
(other.is_a?(Sass::Value::List) &&
other.to_a == to_a &&
other.separator == separator &&
other.bracketed? == bracketed?) ||
(to_a.empty? && other.is_a?(Sass::Value::Map) && other.to_a.empty?)
end
|
#assert_map(name = nil) ⇒ Map
68
69
70
|
# File 'lib/sass/value/list.rb', line 68
def assert_map(name = nil)
to_a.empty? ? Sass::Value::Map.new({}) : super.assert_map(name)
end
|
#at(index) ⇒ Value
43
44
45
46
47
48
49
|
# File 'lib/sass/value/list.rb', line 43
def at(index)
index = index.floor
index = to_a.length + index if index.negative?
return nil if index.negative? || index >= to_a.length
to_a[index]
end
|
#bracketed? ⇒ ::Boolean
28
29
30
|
# File 'lib/sass/value/list.rb', line 28
def bracketed?
@bracketed
end
|
#hash ⇒ Integer
52
53
54
|
# File 'lib/sass/value/list.rb', line 52
def hash
@hash ||= contents.hash
end
|
#to_a ⇒ Array<Value>
57
58
59
|
# File 'lib/sass/value/list.rb', line 57
def to_a
@contents
end
|
#to_map ⇒ Map?
62
63
64
|
# File 'lib/sass/value/list.rb', line 62
def to_map
to_a.empty? ? Sass::Value::Map.new({}) : nil
end
|