Class: Piglet::Field::InfixExpression

Inherits:
Object
  • Object
show all
Includes:
Field
Defined in:
lib/piglet/field/infix_expression.rb

Overview

:nodoc:

Constant Summary

Constants included from Field

Field::FUNCTIONS, Field::SYMBOLIC_OPERATORS

Instance Attribute Summary collapse

Attributes included from Field

#name, #type

Instance Method Summary collapse

Methods included from Field

#and, #as, #cast, #diff, #empty?, #matches, #ne, #neg, #not, #not_null?, #null?, #or

Constructor Details

#initialize(operator, left_expression, right_expression, options = nil) ⇒ InfixExpression

Returns a new instance of InfixExpression.



10
11
12
13
14
15
16
17
18
# File 'lib/piglet/field/infix_expression.rb', line 10

def initialize(operator, left_expression, right_expression, options=nil)
  options ||= {}
  @operator, @left_expression, @right_expression = operator, left_expression, right_expression
  if options[:type]
    @type = options[:type]
  else
    @type = determine_type(@left_expression, @right_expression)
  end
end

Instance Attribute Details

#operatorObject (readonly)

Returns the value of attribute operator.



8
9
10
# File 'lib/piglet/field/infix_expression.rb', line 8

def operator
  @operator
end

Instance Method Details

#simple?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/piglet/field/infix_expression.rb', line 20

def simple?
  false
end

#to_sObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/piglet/field/infix_expression.rb', line 24

def to_s
  left  = @left_expression
  right = @right_expression

  if left.respond_to?(:operator) && left.operator != @operator
    left = parenthesise(left)
  end
  
  if right.respond_to?(:operator) && right.operator != @operator
    right = parenthesise(right)
  end
  
  "#{left} #{@operator} #{right}"
end