Class: Sass::Value::String
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
#[], #assert_boolean, #assert_calculation, #assert_color, #assert_function, #assert_map, #assert_mixin, #assert_number, #at, #bracketed?, #eql?, #sass_index_to_array_index, #separator, #to_a, #to_bool, #to_map, #to_nil
Constructor Details
#initialize(text = '', quoted: true) ⇒ String
Returns a new instance of String.
14
15
16
17
|
# File 'lib/sass/value/string.rb', line 14
def initialize(text = '', quoted: true)
@text = text.freeze
@quoted = quoted
end
|
Instance Attribute Details
#text ⇒ ::String
20
21
22
|
# File 'lib/sass/value/string.rb', line 20
def text
@text
end
|
Instance Method Details
#==(other) ⇒ ::Boolean
28
29
30
|
# File 'lib/sass/value/string.rb', line 28
def ==(other)
other.is_a?(Sass::Value::String) && other.text == text
end
|
#assert_string(_name = nil) ⇒ String
38
39
40
|
# File 'lib/sass/value/string.rb', line 38
def assert_string(_name = nil)
self
end
|
#hash ⇒ Integer
33
34
35
|
# File 'lib/sass/value/string.rb', line 33
def hash
@hash ||= text.hash
end
|
#quoted? ⇒ ::Boolean
23
24
25
|
# File 'lib/sass/value/string.rb', line 23
def quoted?
@quoted
end
|
#sass_index_to_string_index(sass_index, name = nil) ⇒ Integer
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/sass/value/string.rb', line 44
def sass_index_to_string_index(sass_index, name = nil)
index = sass_index.assert_number(name).assert_integer(name)
raise Sass::ScriptError.new('String index may not be 0', name) if index.zero?
if index.abs > text.length
raise Sass::ScriptError.new("Invalid index #{sass_index} for a string with #{text.length} characters", name)
end
index.negative? ? text.length + index : index - 1
end
|
56
57
58
|
# File 'lib/sass/value/string.rb', line 56
def to_s
@quoted ? Serializer.serialize_quoted_string(@text) : Serializer.serialize_unquoted_string(@text)
end
|