Class: Sass::Value::List

Inherits:
Object
  • Object
show all
Includes:
Sass::Value
Defined in:
lib/sass/value/list.rb

Overview

Sass’s list type.

Direct Known Subclasses

ArgumentList

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Sass::Value

#[], #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.

Parameters:

  • contents (Array<Value>) (defaults to: [])
  • separator (::String) (defaults to: ',')
  • bracketed (::Boolean) (defaults to: false)


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? (readonly)

Returns:

  • (::String, nil)


25
26
27
# File 'lib/sass/value/list.rb', line 25

def separator
  @separator
end

Instance Method Details

#==(other) ⇒ ::Boolean

Returns:

  • (::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

Returns:

Raises:



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

Parameters:

  • index (Numeric)

Returns:



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

Returns:

  • (::Boolean)


28
29
30
# File 'lib/sass/value/list.rb', line 28

def bracketed?
  @bracketed
end

#hashInteger

Returns:

  • (Integer)


52
53
54
# File 'lib/sass/value/list.rb', line 52

def hash
  @hash ||= contents.hash
end

#to_aArray<Value>

Returns:



57
58
59
# File 'lib/sass/value/list.rb', line 57

def to_a
  @contents
end

#to_mapMap?

Returns:



62
63
64
# File 'lib/sass/value/list.rb', line 62

def to_map
  to_a.empty? ? Sass::Value::Map.new({}) : nil
end