Class: Sangi::Expression

Inherits:
Object
  • Object
show all
Defined in:
lib/sangi/expression.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left:, operator:, right:, source:) ⇒ Expression

Returns a new instance of Expression.



5
6
7
8
9
10
# File 'lib/sangi/expression.rb', line 5

def initialize(left:, operator:, right:, source:)
  @left = left
  @operator = operator
  @right = right
  @source = source
end

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



3
4
5
# File 'lib/sangi/expression.rb', line 3

def left
  @left
end

#operatorObject (readonly)

Returns the value of attribute operator.



3
4
5
# File 'lib/sangi/expression.rb', line 3

def operator
  @operator
end

#rightObject (readonly)

Returns the value of attribute right.



3
4
5
# File 'lib/sangi/expression.rb', line 3

def right
  @right
end

#sourceObject (readonly)

Returns the value of attribute source.



3
4
5
# File 'lib/sangi/expression.rb', line 3

def source
  @source
end

Instance Method Details

#effective_rightObject



12
13
14
# File 'lib/sangi/expression.rb', line 12

def effective_right
  operator == :- ? -right : right
end

#normalized_sourceObject



16
17
18
# File 'lib/sangi/expression.rb', line 16

def normalized_source
  "#{left} + #{effective_right}"
end