Class: Sass::Script::Value::String
- Defined in:
- lib/sass/script/value/string.rb
Overview
A SassScript object representing a CSS string or a CSS identifier.
Instance Attribute Summary collapse
-
#type ⇒ Symbol
readonly
Whether this is a CSS string or a CSS identifier.
-
#value ⇒ String
readonly
The Ruby value of the string.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(value, type = :identifier) ⇒ String
constructor
Creates a new string.
- #plus(other)
- #to_s(opts = {})
- #to_sass(opts = {})
Methods inherited from Base
#==, #_perform, #assert_int!, #div, #eq, #eql?, #hash, #inspect, #minus, #neq, #null?, #separator, #single_eq, #to_a, #to_bool, #to_h, #to_i, #unary_div, #unary_minus, #unary_not, #unary_plus
Constructor Details
#initialize(value, type = :identifier) ⇒ String
Creates a new string.
20 21 22 23 |
# File 'lib/sass/script/value/string.rb', line 20
def initialize(value, type = :identifier)
super(value)
@type = type
end
|
Instance Attribute Details
#type ⇒ Symbol (readonly)
Whether this is a CSS string or a CSS identifier. The difference is that strings are written with double-quotes, while identifiers aren't.
14 15 16 |
# File 'lib/sass/script/value/string.rb', line 14
def type
@type
end
|
#value ⇒ String (readonly)
The Ruby value of the string.
7 8 9 |
# File 'lib/sass/script/value/string.rb', line 7
def value
@value
end
|
Instance Method Details
#plus(other)
26 27 28 29 |
# File 'lib/sass/script/value/string.rb', line 26
def plus(other)
other_str = other.is_a?(Sass::Script::Value::String) ? other.value : other.to_s
Sass::Script::Value::String.new(value + other_str, type)
end
|
#to_s(opts = {})
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sass/script/value/string.rb', line 32
def to_s(opts = {})
if @type == :identifier
return @value.gsub(/\n\s*/, " ")
end
return "\"#{value.gsub('"', "\\\"")}\"" if opts[:quote] == %q{"}
return "'#{value.gsub("'", "\\'")}'" if opts[:quote] == %q{'}
return "\"#{value}\"" unless value.include?('"')
return "'#{value}'" unless value.include?("'")
"\"#{value.gsub('"', "\\\"")}\"" # '
end
|
#to_sass(opts = {})
45 46 47 |
# File 'lib/sass/script/value/string.rb', line 45
def to_sass(opts = {})
to_s
end
|