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

options[W]

Sets the options hash for this node, as well as for all child nodes. See the official Sass reference for options.

source_range[RW]

The source range in the document on which this node appeared.

value[R]

Returns the pure Ruby value of the value. The type of this value varies based on the subclass.

Public Class Methods

new(value = nil) click to toggle source

Creates a new value.

# File lib/sassc/script/value.rb, line 18
def initialize(value = nil)
  value.freeze unless value.nil? || value == true || value == false
  @value = value
  @options = nil
end

Public Instance Methods

==(other) click to toggle source

Compares this object to ‘other`

# File lib/sassc/script/value.rb, line 59
def ==(other)
  self.class == other.class && value == other.value
end
assert_int!() click to toggle source

@raise [SassC::SyntaxError] if this value isn’t an integer

# File lib/sassc/script/value.rb, line 70
def assert_int!; to_i; end
bracketed() click to toggle source

Whether the value is surrounded by square brackets. For non-list values, this will be ‘false`.

# File lib/sassc/script/value.rb, line 80
def bracketed
  false
end
eql?(other) click to toggle source

True if this Value is the same as ‘other`

# File lib/sassc/script/value.rb, line 44
def eql?(other)
  self == other
end
hash() click to toggle source

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 39
def hash
  value.hash
end
inspect() click to toggle source

Returns a system inspect value for this object

# File lib/sassc/script/value.rb, line 49
def inspect
  value.inspect
end
null?() click to toggle source

Returns ‘false` (all Values are truthy)

# File lib/sassc/script/value.rb, line 112
def null?
  false
end
options() click to toggle source

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 32
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
separator() click to toggle source

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 74
def separator
  nil
end
to_a() click to toggle source

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 86
def to_a
  [self]
end
to_bool() click to toggle source

Returns ‘true` (all Values are truthy)

# File lib/sassc/script/value.rb, line 54
def to_bool
  true
end
to_h() click to toggle source

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 95
def to_h
  raise SassC::SyntaxError.new("#{inspect} is not a map.")
end
to_i() click to toggle source

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 65
def to_i
  raise SassC::SyntaxError.new("#{inspect} is not an integer.")
end
to_s(opts = {}) click to toggle source

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 106
def to_s(opts = {})
  SassC::Util.abstract(self)
end
Also aliased as: to_sass
to_sass(opts = {})
Alias for: to_s
with_contents(contents, separator: self.separator, bracketed: self.bracketed) click to toggle source

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 123
def with_contents(contents, separator: self.separator, bracketed: self.bracketed)
  SassC::Script::Value::List.new(contents, separator: separator, bracketed: bracketed)
end

Protected Instance Methods

_perform(environment) click to toggle source

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 133
def _perform(environment)
  self
end