Class: Sass::Script::Value::Base
- Inherits:
-
Object
- Object
- Sass::Script::Value::Base
- Defined in:
- 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
-
#options ⇒ {Symbol => Object}
Returns the options hash for this node.
-
#source_range ⇒ Sass::Source::Range
The source range in the document on which this node appeared.
-
#value ⇒ Object
readonly
Returns the Ruby value of the value.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares this object with another.
-
#_perform(environment) ⇒ Value
protected
Evaluates the value.
- #assert_int!
-
#div(other) ⇒ Script::Value::String
The SassScript
/
operation. -
#eq(other) ⇒ Sass::Script::Value::Bool
The SassScript
==
operation. - #eql?(other) ⇒ Boolean
-
#hash ⇒ Fixnum
Returns the hash code of this value.
-
#initialize(value = nil) ⇒ Base
constructor
Creates a new value.
-
#inspect ⇒ String
A readable representation of the value.
-
#minus(other) ⇒ Script::Value::String
The SassScript
-
operation. -
#neq(other) ⇒ Sass::Script::Value::Bool
The SassScript
!=
operation. -
#null? ⇒ Boolean
Returns whether or not this object is null.
-
#plus(other) ⇒ Script::Value::String
The SassScript
+
operation. -
#separator ⇒ Symbol
Returns the separator for this value.
-
#single_eq(other) ⇒ Script::Value::String
The SassScript
=
operation (used for proprietary MS syntax likealpha(opacity=20)
). -
#to_a ⇒ Array<Value>
Returns the value of this value as a list.
-
#to_bool ⇒ Boolean
true
(the Ruby boolean value). -
#to_h ⇒ Hash<Value, Value>
Returns the value of this value as a hash.
-
#to_i ⇒ Fixnum
The integer value of this value.
-
#to_s(opts = {}) ⇒ String
(also: #to_sass)
Returns the string representation of this value as it would be output to the CSS document.
-
#unary_div ⇒ Script::Value::String
The SassScript unary
/
operation (e.g./$a
). -
#unary_minus ⇒ Script::Value::String
The SassScript unary
-
operation (e.g.-$a
). -
#unary_not ⇒ Sass::Script::Value::Bool
The SassScript
==
operation. -
#unary_plus ⇒ Script::Value::String
The SassScript unary
+
operation (e.g.+$a
).
Constructor Details
#initialize(value = nil) ⇒ Base
Creates a new value.
22 23 24 25 |
# File 'lib/sass/script/value/base.rb', line 22
def initialize(value = nil)
value.freeze unless value.nil? || value == true || value == false
@value = value
end
|
Instance Attribute Details
#options ⇒ {Symbol => Object}
Returns the options hash for this node.
40 41 42 43 44 45 46 47 48 |
# File 'lib/sass/script/value/base.rb', line 40
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
|
#source_range ⇒ Sass::Source::Range
The source range in the document on which this node appeared.
17 18 19 |
# File 'lib/sass/script/value/base.rb', line 17
def source_range
@source_range
end
|
#value ⇒ Object (readonly)
Returns the Ruby value of the value. The type of this value varies based on the subclass.
12 13 14 |
# File 'lib/sass/script/value/base.rb', line 12
def value
@value
end
|
Instance Method Details
#==(other) ⇒ Boolean
Compares this object with another.
176 177 178 |
# File 'lib/sass/script/value/base.rb', line 176
def ==(other)
eq(other).to_bool
end
|
#_perform(environment) ⇒ Value (protected)
Evaluates the value.
235 236 237 |
# File 'lib/sass/script/value/base.rb', line 235
def _perform(environment)
self
end
|
#assert_int!
187 |
# File 'lib/sass/script/value/base.rb', line 187
def assert_int!; to_i; end
|
#div(other) ⇒ Script::Value::String
The SassScript /
operation.
119 120 121 |
# File 'lib/sass/script/value/base.rb', line 119
def div(other)
Sass::Script::Value::String.new("#{to_s}/#{other.to_s}")
end
|
#eq(other) ⇒ Sass::Script::Value::Bool
The SassScript ==
operation.
Note that this returns a Sass::Script::Value::Bool object,
not a Ruby boolean.
57 58 59 |
# File 'lib/sass/script/value/base.rb', line 57
def eq(other)
Sass::Script::Value::Bool.new(self.class == other.class && value == other.value)
end
|
#eql?(other) ⇒ Boolean
158 159 160 |
# File 'lib/sass/script/value/base.rb', line 158
def eql?(other)
self == other
end
|
#hash ⇒ Fixnum
Returns the hash code of this value. Two objects' hash codes should be equal if the objects are equal.
154 155 156 |
# File 'lib/sass/script/value/base.rb', line 154
def hash
value.hash
end
|
#inspect ⇒ String
Returns A readable representation of the value.
163 164 165 |
# File 'lib/sass/script/value/base.rb', line 163
def inspect
value.inspect
end
|
#minus(other) ⇒ Script::Value::String
The SassScript -
operation.
110 111 112 |
# File 'lib/sass/script/value/base.rb', line 110
def minus(other)
Sass::Script::Value::String.new("#{to_s}-#{other.to_s}")
end
|
#neq(other) ⇒ Sass::Script::Value::Bool
The SassScript !=
operation.
Note that this returns a Sass::Script::Value::Bool object,
not a Ruby boolean.
68 69 70 |
# File 'lib/sass/script/value/base.rb', line 68
def neq(other)
Sass::Script::Value::Bool.new(!eq(other).to_bool)
end
|
#null? ⇒ Boolean
Returns whether or not this object is null.
225 226 227 |
# File 'lib/sass/script/value/base.rb', line 225
def null?
false
end
|
#plus(other) ⇒ Script::Value::String
The SassScript +
operation.
98 99 100 101 102 103 |
# File 'lib/sass/script/value/base.rb', line 98
def plus(other)
if other.is_a?(Sass::Script::Value::String)
return Sass::Script::Value::String.new(to_s + other.value, other.type)
end
Sass::Script::Value::String.new(to_s + other.to_s)
end
|
#separator ⇒ Symbol
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
.
194 |
# File 'lib/sass/script/value/base.rb', line 194
def separator; nil; end
|
#single_eq(other) ⇒ Script::Value::String
The SassScript =
operation
(used for proprietary MS syntax like alpha(opacity=20)
).
89 90 91 |
# File 'lib/sass/script/value/base.rb', line 89
def single_eq(other)
Sass::Script::Value::String.new("#{to_s}=#{other.to_s}")
end
|
#to_a ⇒ Array<Value>
Returns the value of this value as a list. Single values are considered the same as single-element lists.
200 201 202 |
# File 'lib/sass/script/value/base.rb', line 200
def to_a
[self]
end
|
#to_bool ⇒ Boolean
Returns true
(the Ruby boolean value).
168 169 170 |
# File 'lib/sass/script/value/base.rb', line 168
def to_bool
true
end
|
#to_h ⇒ Hash<Value, Value>
Returns the value of this value as a hash. Most values don't have hash representations, but [Map]s and empty [List]s do.
209 210 211 |
# File 'lib/sass/script/value/base.rb', line 209
def to_h
raise Sass::SyntaxError.new("#{inspect} is not a map.")
end
|
#to_i ⇒ Fixnum
Returns The integer value of this value.
182 183 184 |
# File 'lib/sass/script/value/base.rb', line 182
def to_i
raise Sass::SyntaxError.new("#{inspect} is not an integer.")
end
|
#to_s(opts = {}) ⇒ String Also known as: to_sass
Returns the string representation of this value as it would be output to the CSS document.
217 218 219 |
# File 'lib/sass/script/value/base.rb', line 217
def to_s(opts = {})
Sass::Util.abstract(self)
end
|
#unary_div ⇒ Script::Value::String
The SassScript unary /
operation (e.g. /$a
).
146 147 148 |
# File 'lib/sass/script/value/base.rb', line 146
def unary_div
Sass::Script::Value::String.new("/#{to_s}")
end
|
#unary_minus ⇒ Script::Value::String
The SassScript unary -
operation (e.g. -$a
).
137 138 139 |
# File 'lib/sass/script/value/base.rb', line 137
def unary_minus
Sass::Script::Value::String.new("-#{to_s}")
end
|
#unary_not ⇒ Sass::Script::Value::Bool
The SassScript ==
operation.
Note that this returns a Sass::Script::Value::Bool object,
not a Ruby boolean.
79 80 81 |
# File 'lib/sass/script/value/base.rb', line 79
def unary_not
Sass::Script::Value::Bool.new(!to_bool)
end
|
#unary_plus ⇒ Script::Value::String
The SassScript unary +
operation (e.g. +$a
).
128 129 130 |
# File 'lib/sass/script/value/base.rb', line 128
def unary_plus
Sass::Script::Value::String.new("+#{to_s}")
end
|