Class: Sass::Script::Value::Base
- Inherits:
- Object
- Object
- Sass::Script::Value::Base
- Defined in:
- /Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb
Overview
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.
Instance Attribute Summary (collapse)
- - ({Symbol => Object}) options
Returns the options hash for this node.
- - (Sass::Source::Range) source_range
The source range in the document on which this node appeared.
- - (Object) value readonly
Returns the Ruby value of the value.
Instance Method Summary (collapse)
- - (Boolean) ==(other)
Compares this object with another.
- - (Value) _perform(environment) protected
Evaluates the value.
- - assert_int!
- - (Script::Value::String) div(other)
The SassScript
/
operation. - - (Sass::Script::Value::Bool) eq(other)
The SassScript
==
operation. - - (Boolean) eql?(other)
- - (Fixnum) hash
Returns the hash code of this value.
- - (Base) initialize(value = nil) constructor
Creates a new value.
- - (String) inspect
A readable representation of the value.
- - (Script::Value::String) minus(other)
The SassScript
-
operation. - - (Sass::Script::Value::Bool) neq(other)
The SassScript
!=
operation. - - (Boolean) null?
Returns whether or not this object is null.
- - (Script::Value::String) plus(other)
The SassScript
+
operation. - - (Symbol) separator
Returns the separator for this value.
- - (Script::Value::String) single_eq(other)
The SassScript
=
operation (used for proprietary MS syntax likealpha(opacity=20)
). - - (Array<Value>) to_a
Returns the value of this value as a list.
- - (Boolean) to_bool
true
(the Ruby boolean value). - - (Hash<Value, Value>) to_h
Returns the value of this value as a hash.
- - (Fixnum) to_i
The integer value of this value.
- - (String) to_s(opts = {}) (also: #to_sass)
Returns the string representation of this value as it would be output to the CSS document.
- - (Script::Value::String) unary_div
The SassScript unary
/
operation (e.g./$a
). - - (Script::Value::String) unary_minus
The SassScript unary
-
operation (e.g.-$a
). - - (Sass::Script::Value::Bool) unary_not
The SassScript
==
operation. - - (Script::Value::String) unary_plus
The SassScript unary
+
operation (e.g.+$a
).
Constructor Details
- (Base) initialize(value = nil)
Creates a new value.
22 23 24 25 26 | # File '/Users/ceppstei/Projects/sass-lang/.sass/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 |
Instance Attribute Details
- ({Symbol => Object}) options
Returns the options hash for this node.
41 42 43 44 45 46 47 48 49 | # File '/Users/ceppstei/Projects/sass-lang/.sass/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 |
- (Sass::Source::Range) source_range
The source range in the document on which this node appeared.
17 18 19 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 17
def source_range
@source_range
end |
- (Object) value (readonly)
Returns the Ruby value of the value. The type of this value varies based on the subclass.
12 13 14 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 12
def value
@value
end |
Instance Method Details
- (Boolean) ==(other)
Compares this object with another.
175 176 177 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 175
def ==(other)
eq(other).to_bool
end |
- (Value) _perform(environment) (protected)
Evaluates the value.
237 238 239 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 237
def _perform(environment)
self
end |
- assert_int!
186 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 186
def assert_int!; to_i; end |
- (Script::Value::String) div(other)
The SassScript /
operation.
118 119 120 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 118
def div(other)
Sass::Script::Value::String.new("#{self}/#{other}")
end |
- (Sass::Script::Value::Bool) eq(other)
The SassScript ==
operation. Note that this returns a Sass::Script::Value::Bool object, not a Ruby boolean.
58 59 60 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 58
def eq(other)
Sass::Script::Value::Bool.new(self.class == other.class && value == other.value)
end |
- (Boolean) eql?(other)
157 158 159 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 157
def eql?(other)
self == other
end |
- (Fixnum) hash
Returns the hash code of this value. Two objects’ hash codes should be equal if the objects are equal.
153 154 155 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 153
def hash
value.hash
end |
- (String) inspect
Returns A readable representation of the value
162 163 164 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 162
def inspect
value.inspect
end |
- (Script::Value::String) minus(other)
The SassScript -
operation.
109 110 111 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 109
def minus(other)
Sass::Script::Value::String.new("#{self}-#{other}")
end |
- (Sass::Script::Value::Bool) neq(other)
The SassScript !=
operation. Note that this returns a Sass::Script::Value::Bool object, not a Ruby boolean.
69 70 71 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 69
def neq(other)
Sass::Script::Value::Bool.new(!eq(other).to_bool)
end |
- (Boolean) null?
Returns whether or not this object is null.
227 228 229 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 227
def null?
false
end |
- (Script::Value::String) plus(other)
The SassScript +
operation.
99 100 101 102 | # File '/Users/ceppstei/Projects/sass-lang/.sass/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 |
- (Symbol) separator
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
.
193 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 193
def separator; nil; end |
- (Script::Value::String) single_eq(other)
The SassScript =
operation (used for proprietary MS syntax like alpha(opacity=20)
).
90 91 92 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 90
def single_eq(other)
Sass::Script::Value::String.new("#{self}=#{other}")
end |
- (Array<Value>) to_a
Returns the value of this value as a list. Single values are considered the same as single-element lists.
199 200 201 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 199
def to_a
[self]
end |
- (Boolean) to_bool
Returns true
(the Ruby boolean value)
167 168 169 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 167
def to_bool
true
end |
- (Hash<Value, Value>) to_h
Returns the value of this value as a hash. Most values don’t have hash representations, but [Map]s and empty [List]s do.
208 209 210 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 208
def to_h
raise Sass::SyntaxError.new("#{inspect} is not a map.")
end |
- (Fixnum) to_i
Returns The integer value of this value
181 182 183 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 181
def to_i
raise Sass::SyntaxError.new("#{inspect} is not an integer.")
end |
- (String) to_s(opts = {}) Also known as: to_sass
Returns the string representation of this value as it would be output to the CSS document.
219 220 221 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 219
def to_s(opts = {})
Sass::Util.abstract(self)
end |
- (Script::Value::String) unary_div
The SassScript unary /
operation (e.g. /$a
).
145 146 147 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 145
def unary_div
Sass::Script::Value::String.new("/#{self}")
end |
- (Script::Value::String) unary_minus
The SassScript unary -
operation (e.g. -$a
).
136 137 138 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 136
def unary_minus
Sass::Script::Value::String.new("-#{self}")
end |
- (Sass::Script::Value::Bool) unary_not
The SassScript ==
operation. Note that this returns a Sass::Script::Value::Bool object, not a Ruby boolean.
80 81 82 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 80
def unary_not
Sass::Script::Value::Bool.new(!to_bool)
end |
- (Script::Value::String) unary_plus
The SassScript unary +
operation (e.g. +$a
).
127 128 129 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/base.rb', line 127
def unary_plus
Sass::Script::Value::String.new("+#{self}")
end |