class SassC::Script::Value
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 the official Sass reference for options.
The source range in the document on which this node appeared.
Returns the pure Ruby value of the value. The type of this value varies based on the subclass.
Public Class Methods
Creates a new value.
# File lib/sassc/script/value.rb, line 17 def initialize(value = nil) value.freeze unless value.nil? || value == true || value == false @value = value @options = nil end
Public Instance Methods
Compares this object to `other`
# File lib/sassc/script/value.rb, line 58 def ==(other) self.class == other.class && value == other.value end
@raise [SassC::SyntaxError] if this value isn't an integer
# File lib/sassc/script/value.rb, line 69 def assert_int!; to_i; end
Whether the value is surrounded by square brackets. For non-list values, this will be `false`.
# File lib/sassc/script/value.rb, line 79 def bracketed false end
True if this Value is the same as `other`
# File lib/sassc/script/value.rb, line 43 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.
# File lib/sassc/script/value.rb, line 38 def hash value.hash end
Returns a system inspect value for this object
# File lib/sassc/script/value.rb, line 48 def inspect value.inspect end
Returns `false` (all Values are truthy)
# File lib/sassc/script/value.rb, line 111 def null? false end
Returns the options hash for this node. Raises SassC::SyntaxError if the value was created outside of the parser and {#to_s} was called on it
# File lib/sassc/script/value.rb, line 31 def options return @options if @options raise SassC::SyntaxError.new("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.") 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`.
# File lib/sassc/script/value.rb, line 73 def separator nil end
Returns the value of this Value as an array. Single Values are considered the same as single-element arrays.
# File lib/sassc/script/value.rb, line 85 def to_a [self] end
Returns `true` (all Values are truthy)
# File lib/sassc/script/value.rb, line 53 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 [SassC::SyntaxError] if this value doesn't have a hash representation
# File lib/sassc/script/value.rb, line 94 def to_h raise SassC::SyntaxError.new("#{inspect} is not a map.") end
Returns the integer value of this value. Raises SassC::SyntaxError if this value doesn’t implment integer conversion.
# File lib/sassc/script/value.rb, line 64 def to_i raise SassC::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/sassc/script/value.rb, line 105 def to_s(opts = {}) SassC::Util.abstract(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/sassc/script/value.rb, line 122 def with_contents(contents, separator: self.separator, bracketed: self.bracketed) SassC::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/sassc/script/value.rb, line 132 def _perform(environment) self end