Class: Sass::Script::UnaryOperation
- Defined in:
- lib/sass/script/unary_operation.rb
Overview
A SassScript parse node representing a unary operation,
such as -$b
or not true
.
Currently only -
, /
, and not
are unary operators.
Instance Attribute Summary
Attributes inherited from Node
Instance Method Summary collapse
-
#_perform(environment) ⇒ Literal
protected
Evaluates the operation.
-
#children ⇒ Array<Node>
Returns the operand of the operation.
- #deep_copy
-
#initialize(operand, operator) ⇒ UnaryOperation
constructor
A new instance of UnaryOperation.
-
#inspect ⇒ String
A human-readable s-expression representation of the operation.
- #to_sass(opts = {})
Methods inherited from Node
Constructor Details
#initialize(operand, operator) ⇒ UnaryOperation
Returns a new instance of UnaryOperation.
10 11 12 13 14 |
# File 'lib/sass/script/unary_operation.rb', line 10
def initialize(operand, operator)
@operand = operand
@operator = operator
super()
end
|
Instance Method Details
#_perform(environment) ⇒ Literal (protected)
Evaluates the operation.
55 56 57 58 59 60 61 62 |
# File 'lib/sass/script/unary_operation.rb', line 55
def _perform(environment)
operator = "unary_#{@operator}"
literal = @operand.perform(environment)
literal.send(operator)
rescue NoMethodError => e
raise e unless e.name.to_s == operator.to_s
raise Sass::SyntaxError.new("Undefined unary operation: \"#{@operator} #{literal}\".")
end
|
#children ⇒ Array<Node>
Returns the operand of the operation.
37 38 39 |
# File 'lib/sass/script/unary_operation.rb', line 37
def children
[@operand]
end
|
#deep_copy
42 43 44 45 46 |
# File 'lib/sass/script/unary_operation.rb', line 42
def deep_copy
node = dup
node.instance_variable_set('@operand', @operand.deep_copy)
node
end
|
#inspect ⇒ String
Returns A human-readable s-expression representation of the operation.
17 18 19 |
# File 'lib/sass/script/unary_operation.rb', line 17
def inspect
"(#{@operator.inspect} #{@operand.inspect})"
end
|
#to_sass(opts = {})
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sass/script/unary_operation.rb', line 22
def to_sass(opts = {})
operand = @operand.to_sass(opts)
if @operand.is_a?(Operation) ||
(@operator == :minus &&
(operand =~ Sass::SCSS::RX::IDENT) == 0)
operand = "(#{@operand.to_sass(opts)})"
end
op = Lexer::OPERATORS_REVERSE[@operator]
op + (op =~ /[a-z]/ ? " " : "") + operand
end
|