Class: Sass::Value::List
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
#[], #assert_boolean, #assert_calculation, #assert_color, #assert_function, #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
#contents ⇒ Array<Value>
Also known as:
to_a
25
26
27
|
# File 'lib/sass/value/list.rb', line 25
def contents
@contents
end
|
#separator ⇒ ::String?
28
29
30
|
# File 'lib/sass/value/list.rb', line 28
def separator
@separator
end
|
Instance Method Details
#==(other) ⇒ ::Boolean
36
37
38
39
40
41
42
|
# File 'lib/sass/value/list.rb', line 36
def ==(other)
(other.is_a?(Sass::Value::List) &&
other.contents == contents &&
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
46
47
48
49
50
51
52
|
# File 'lib/sass/value/list.rb', line 46
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
31
32
33
|
# File 'lib/sass/value/list.rb', line 31
def bracketed?
@bracketed
end
|
#hash ⇒ Integer
55
56
57
|
# File 'lib/sass/value/list.rb', line 55
def hash
@hash ||= contents.hash
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
|