Class: Sass::Script::Tree::UnaryOperation

Inherits:
Node
  • Object
show all
Defined in:
/home/nweiz/code/sass-site/.sass/lib/sass/script/tree/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 (collapse)

Attributes inherited from Node

#filename, #line, #options, #source_range

Instance Method Summary (collapse)

Methods inherited from Node

#dasherize, #force_division!, #opts, #perform

Constructor Details

- (UnaryOperation) initialize(operand, operator)

Returns a new instance of UnaryOperation

Parameters:



15
16
17
18
19
# File '/home/nweiz/code/sass-site/.sass/lib/sass/script/tree/unary_operation.rb', line 15

def initialize(operand, operator)
  @operand = operand
  @operator = operator
  super()
end

Instance Attribute Details

- (Script::Node) operand (readonly)

Returns The parse-tree node for the object of the operator

Returns:

  • (Script::Node)

    The parse-tree node for the object of the operator



11
12
13
# File '/home/nweiz/code/sass-site/.sass/lib/sass/script/tree/unary_operation.rb', line 11

def operand
  @operand
end

- (Symbol) operator (readonly)

Returns The operation to perform

Returns:

  • (Symbol)

    The operation to perform



8
9
10
# File '/home/nweiz/code/sass-site/.sass/lib/sass/script/tree/unary_operation.rb', line 8

def operator
  @operator
end

Instance Method Details

- (Sass::Script::Value) _perform(environment) (protected)

Evaluates the operation.

Parameters:

  • environment (Sass::Environment)

    The environment in which to evaluate the SassScript

Returns:

Raises:



60
61
62
63
64
65
66
67
# File '/home/nweiz/code/sass-site/.sass/lib/sass/script/tree/unary_operation.rb', line 60

def _perform(environment)
  operator = "unary_#{@operator}"
  value = @operand.perform(environment)
  value.send(operator)
rescue NoMethodError => e
  raise e unless e.name.to_s == operator.to_s
  raise Sass::SyntaxError.new("Undefined unary operation: \"#{@operator} #{value}\".")
end

- (Array<Node>) children

Returns the operand of the operation.

Returns:

See Also:



42
43
44
# File '/home/nweiz/code/sass-site/.sass/lib/sass/script/tree/unary_operation.rb', line 42

def children
  [@operand]
end

- deep_copy

See Also:



47
48
49
50
51
# File '/home/nweiz/code/sass-site/.sass/lib/sass/script/tree/unary_operation.rb', line 47

def deep_copy
  node = dup
  node.instance_variable_set('@operand', @operand.deep_copy)
  node
end

- (String) inspect

Returns A human-readable s-expression representation of the operation

Returns:

  • (String)

    A human-readable s-expression representation of the operation



22
23
24
# File '/home/nweiz/code/sass-site/.sass/lib/sass/script/tree/unary_operation.rb', line 22

def inspect
  "(#{@operator.inspect} #{@operand.inspect})"
end

- to_sass(opts = {})

See Also:



27
28
29
30
31
32
33
34
35
36
# File '/home/nweiz/code/sass-site/.sass/lib/sass/script/tree/unary_operation.rb', line 27

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 = Sass::Script::Lexer::OPERATORS_REVERSE[@operator]
  op + (op =~ /[a-z]/ ? " " : "") + operand
end