Class: Sass::Script::Literal
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
-
#value ⇒ Object
readonly
Returns the Ruby value of the literal.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares this object with another.
-
#and(other) ⇒ Literal
The SassScript
and
operation. - #assert_int!
-
#children ⇒ Array<Node>
Returns an empty array.
-
#comma(other) ⇒ Script::String
The SassScript
,
operation (e.g.!a, !b
,"foo", "bar"
). -
#concat(other) ⇒ Script::String
The SassScript default operation (e.g.
!a !b
,"foo" "bar"
). -
#div(other) ⇒ Script::String
The SassScript
/
operation. -
#eq(other) ⇒ Bool
The SassScript
==
operation. -
#initialize(value = nil) ⇒ Literal
constructor
Creates a new literal.
-
#inspect ⇒ String
A readable representation of the literal.
-
#minus(other) ⇒ Script::String
The SassScript
-
operation. -
#neq(other) ⇒ Bool
The SassScript
!=
operation. -
#options ⇒ {Symbol => Object}
Returns the options hash for this node.
-
#or(other) ⇒ Literal
The SassScript
or
operation. -
#perform(environment) ⇒ Literal
Evaluates the literal.
-
#plus(other) ⇒ Script::String
The SassScript
+
operation. -
#to_bool ⇒ Boolean
true
(the Ruby boolean value). -
#to_i ⇒ Fixnum
The integer value of this literal.
-
#to_s ⇒ String
Returns the string representation of this literal as it would be output to the CSS document.
-
#unary_div ⇒ Script::String
The SassScript unary
/
operation (e.g./!a
). -
#unary_minus ⇒ Script::String
The SassScript unary
-
operation (e.g.-!a
). -
#unary_not ⇒ Bool
The SassScript
==
operation.
Constructor Details
#initialize(value = nil) ⇒ Literal
Creates a new literal.
22 23 24 |
# File 'lib/sass/script/literal.rb', line 22
def initialize(value = nil)
@value = value
end
|
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the Ruby value of the literal. The type of this value varies based on the subclass.
17 18 19 |
# File 'lib/sass/script/literal.rb', line 17
def value
@value
end
|
Instance Method Details
#==(other) ⇒ Boolean
Compares this object with another.
189 190 191 |
# File 'lib/sass/script/literal.rb', line 189
def ==(other)
eq(other).to_bool
end
|
#and(other) ⇒ Literal
The SassScript and
operation.
65 66 67 |
# File 'lib/sass/script/literal.rb', line 65
def and(other)
to_bool ? other : self
end
|
#assert_int!
200 |
# File 'lib/sass/script/literal.rb', line 200
def assert_int!; to_i; end
|
#children ⇒ Array<Node>
Returns an empty array.
38 39 40 |
# File 'lib/sass/script/literal.rb', line 38
def children
[]
end
|
#comma(other) ⇒ Script::String
The SassScript ,
operation (e.g. !a, !b
, "foo", "bar"
).
126 127 128 |
# File 'lib/sass/script/literal.rb', line 126
def comma(other)
Sass::Script::String.new("#{self.to_s}, #{other.to_s}")
end
|
#concat(other) ⇒ Script::String
The SassScript default operation (e.g. !a !b
, "foo" "bar"
).
117 118 119 |
# File 'lib/sass/script/literal.rb', line 117
def concat(other)
Sass::Script::String.new("#{self.to_s} #{other.to_s}")
end
|
#div(other) ⇒ Script::String
The SassScript /
operation.
153 154 155 |
# File 'lib/sass/script/literal.rb', line 153
def div(other)
Sass::Script::String.new("#{self.to_s}/#{other.to_s}")
end
|
#eq(other) ⇒ Bool
The SassScript ==
operation.
Note that this returns a Bool object,
not a Ruby boolean.
86 87 88 |
# File 'lib/sass/script/literal.rb', line 86
def eq(other)
Sass::Script::Bool.new(self.class == other.class && self.value == other.value)
end
|
#inspect ⇒ String
Returns A readable representation of the literal.
176 177 178 |
# File 'lib/sass/script/literal.rb', line 176
def inspect
value.inspect
end
|
#minus(other) ⇒ Script::String
The SassScript -
operation.
144 145 146 |
# File 'lib/sass/script/literal.rb', line 144
def minus(other)
Sass::Script::String.new("#{self.to_s}-#{other.to_s}")
end
|
#neq(other) ⇒ Bool
The SassScript !=
operation.
Note that this returns a Bool object,
not a Ruby boolean.
97 98 99 |
# File 'lib/sass/script/literal.rb', line 97
def neq(other)
Sass::Script::Bool.new(!eq(other).to_bool)
end
|
#options ⇒ {Symbol => Object}
Returns the options hash for this node.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/sass/script/literal.rb', line 48
def options
opts = super
return opts if opts
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 literal within a custom Sass function without first
setting the #option attribute.
MSG
end
|
#or(other) ⇒ Literal
The SassScript or
operation.
75 76 77 |
# File 'lib/sass/script/literal.rb', line 75
def or(other)
to_bool ? self : other
end
|
#perform(environment) ⇒ Literal
Evaluates the literal.
30 31 32 |
# File 'lib/sass/script/literal.rb', line 30
def perform(environment)
self
end
|
#plus(other) ⇒ Script::String
The SassScript +
operation.
135 136 137 |
# File 'lib/sass/script/literal.rb', line 135
def plus(other)
Sass::Script::String.new(self.to_s + other.to_s)
end
|
#to_bool ⇒ Boolean
Returns true
(the Ruby boolean value).
181 182 183 |
# File 'lib/sass/script/literal.rb', line 181
def to_bool
true
end
|
#to_i ⇒ Fixnum
Returns The integer value of this literal.
195 196 197 |
# File 'lib/sass/script/literal.rb', line 195
def to_i
raise Sass::SyntaxError.new("#{self.inspect} is not an integer.")
end
|
#to_s ⇒ String
Returns the string representation of this literal as it would be output to the CSS document.
206 207 208 |
# File 'lib/sass/script/literal.rb', line 206
def to_s
raise Sass::SyntaxError.new("[BUG] All subclasses of Sass::Literal must implement #to_s.")
end
|
#unary_div ⇒ Script::String
The SassScript unary /
operation (e.g. /!a
).
171 172 173 |
# File 'lib/sass/script/literal.rb', line 171
def unary_div
Sass::Script::String.new("/#{self.to_s}")
end
|
#unary_minus ⇒ Script::String
The SassScript unary -
operation (e.g. -!a
).
162 163 164 |
# File 'lib/sass/script/literal.rb', line 162
def unary_minus
Sass::Script::String.new("-#{self.to_s}")
end
|