class Sass::Script::Value::Base
The abstract superclass for SassScript objects.
Many of these methods, especially the ones that correspond to SassScript operations, are designed to be overridden by subclasses which may change the semantics somewhat. The operations listed here are just the defaults.
Attributes
Sets the options hash for this node, as well as for all child nodes. See {file:SASS_REFERENCE.md#Options the Sass
options documentation}.
@param options [{Symbol => Object}] The options
The source range in the document on which this node appeared.
@return [Sass::Source::Range]
Returns the Ruby value of the value. The type of this value varies based on the subclass.
@return [Object]
Public Class Methods
Creates a new value.
@param value [Object] The object for {#value}
# File lib/sass/script/value/base.rb, line 22 def initialize(value = nil) value.freeze unless value.nil? || value == true || value == false @value = value @options = nil end
Public Instance Methods
Compares this object with another.
@param other [Object] The object to compare with @return [Boolean] Whether or not this value is equivalent to ‘other`
# File lib/sass/script/value/base.rb, line 175 def ==(other) eq(other).to_bool end
@raise [Sass::SyntaxError] if this value isn’t an integer
# File lib/sass/script/value/base.rb, line 186 def assert_int!; to_i; end
Whether the value is surrounded by square brackets. For non-list values, this will be ‘false`.
@return [Boolean]
# File lib/sass/script/value/base.rb, line 199 def bracketed; false; end
The SassScript ‘/` operation.
@param other [Value] The right-hand side of the operator @return [Script::Value::String] A string containing both values
separated by `"/"`
# File lib/sass/script/value/base.rb, line 118 def div(other) Sass::Script::Value::String.new("#{self}/#{other}") end
The SassScript ‘==` operation. **Note that this returns a {Sass::Script::Value::Bool} object, not a Ruby boolean**.
@param other [Value] The right-hand side of the operator @return [Sass::Script::Value::Bool] True if this value is the same as the other,
false otherwise
# File lib/sass/script/value/base.rb, line 58 def eq(other) Sass::Script::Value::Bool.new(self.class == other.class && value == other.value) end
# File lib/sass/script/value/base.rb, line 157 def eql?(other) self == other end
Returns the hash code of this value. Two objects’ hash codes should be equal if the objects are equal.
@return [Integer for Ruby 2.4.0+, Fixnum for earlier Ruby versions] The hash code.
# File lib/sass/script/value/base.rb, line 153 def hash value.hash end
@return [String] A readable representation of the value
# File lib/sass/script/value/base.rb, line 162 def inspect value.inspect end
The SassScript ‘-` operation.
@param other [Value] The right-hand side of the operator @return [Script::Value::String] A string containing both values
separated by `"-"`
# File lib/sass/script/value/base.rb, line 109 def minus(other) Sass::Script::Value::String.new("#{self}-#{other}") end
The SassScript ‘!=` operation. **Note that this returns a {Sass::Script::Value::Bool} object, not a Ruby boolean**.
@param other [Value] The right-hand side of the operator @return [Sass::Script::Value::Bool] False if this value is the same as the other,
true otherwise
# File lib/sass/script/value/base.rb, line 69 def neq(other) Sass::Script::Value::Bool.new(!eq(other).to_bool) end
Returns whether or not this object is null.
@return [Boolean] ‘false`
# File lib/sass/script/value/base.rb, line 233 def null? false end
Returns the options hash for this node.
@return [{Symbol => Object}] @raise [Sass::SyntaxError] if the options hash hasn’t been set.
This should only happen when the value was created outside of the parser and \{#to\_s} was called on it
# File lib/sass/script/value/base.rb, line 41 def options return @options if @options raise Sass::SyntaxError.new(<<MSG) The #options attribute is not set on this #{self.class}. This error is probably occurring because #to_s was called on this value within a custom Sass function without first setting the #options attribute. MSG end
The SassScript ‘+` operation.
@param other [Value] The right-hand side of the operator @return [Script::Value::String] A string containing both values
without any separation
# File lib/sass/script/value/base.rb, line 99 def plus(other) type = other.is_a?(Sass::Script::Value::String) ? other.type : :identifier Sass::Script::Value::String.new(to_s(:quote => :none) + other.to_s(:quote => :none), type) end
Returns the separator for this value. For non-list-like values or the empty list, this will be ‘nil`. For lists or maps, it will be `:space` or `:comma`.
@return [Symbol]
# File lib/sass/script/value/base.rb, line 193 def separator; nil; end
The SassScript ‘=` operation (used for proprietary MS syntax like `alpha(opacity=20)`).
@param other [Value] The right-hand side of the operator @return [Script::Value::String] A string containing both values
separated by `"="`
# File lib/sass/script/value/base.rb, line 90 def single_eq(other) Sass::Script::Value::String.new("#{self}=#{other}") end
Returns the value of this value as a list. Single values are considered the same as single-element lists.
@return [Array<Value>] This value as a list
# File lib/sass/script/value/base.rb, line 205 def to_a [self] end
@return [Boolean] ‘true` (the Ruby boolean value)
# File lib/sass/script/value/base.rb, line 167 def to_bool true end
Returns the value of this value as a hash. Most values don’t have hash representations, but [Map]s and empty [List]s do.
@return [Hash<Value, Value>] This value as a hash @raise [Sass::SyntaxError] if this value doesn’t have a hash representation
# File lib/sass/script/value/base.rb, line 214 def to_h raise Sass::SyntaxError.new("#{inspect} is not a map.") end
@return [Integer] The integer value of this value @raise [Sass::SyntaxError] if this value isn’t an integer
# File lib/sass/script/value/base.rb, line 181 def to_i raise Sass::SyntaxError.new("#{inspect} is not an integer.") end
Returns the string representation of this value as it would be output to the CSS
document.
@options opts :quote [String]
The preferred quote style for quoted strings. If `:none`, strings are always emitted unquoted.
@return [String]
# File lib/sass/script/value/base.rb, line 225 def to_s(opts = {}) Sass::Util.abstract(self) end
The SassScript unary ‘/` operation (e.g. `/$a`).
@param other [Value] The right-hand side of the operator @return [Script::Value::String] A string containing the value
preceded by `"/"`
# File lib/sass/script/value/base.rb, line 145 def unary_div Sass::Script::Value::String.new("/#{self}") end
The SassScript unary ‘-` operation (e.g. `-$a`).
@param other [Value] The right-hand side of the operator @return [Script::Value::String] A string containing the value
preceded by `"-"`
# File lib/sass/script/value/base.rb, line 136 def unary_minus Sass::Script::Value::String.new("-#{self}") end
The SassScript ‘==` operation. **Note that this returns a {Sass::Script::Value::Bool} object, not a Ruby boolean**.
@param other [Value] The right-hand side of the operator @return [Sass::Script::Value::Bool] True if this value is the same as the other,
false otherwise
# File lib/sass/script/value/base.rb, line 80 def unary_not Sass::Script::Value::Bool.new(!to_bool) end
The SassScript unary ‘+` operation (e.g. `+$a`).
@param other [Value] The right-hand side of the operator @return [Script::Value::String] A string containing the value
preceded by `"+"`
# File lib/sass/script/value/base.rb, line 127 def unary_plus Sass::Script::Value::String.new("+#{self}") end
Creates a new list containing ‘contents` but with the same brackets and separators as this object, when interpreted as a list.
@param contents [Array<Value>] The contents of the new list. @param separator [Symbol] The separator of the new list. Defaults to {#separator}. @param bracketed [Boolean] Whether the new list is bracketed. Defaults to {#bracketed}. @return [Sass::Script::Value::List]
# File lib/sass/script/value/base.rb, line 244 def with_contents(contents, separator: self.separator, bracketed: self.bracketed) Sass::Script::Value::List.new(contents, separator: separator, bracketed: bracketed) end
Protected Instance Methods
Evaluates the value.
@param environment [Sass::Environment] The environment in which to evaluate the SassScript @return [Value] This value
# File lib/sass/script/value/base.rb, line 254 def _perform(environment) self end