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, #predecessors, #type

Instance Method Summary collapse

Methods included from Field

#and, #as, #cast, #diff, #distinct, #empty?, #field, #field_alias, #filter, #flatten, #generate_field_alias, #get, #limit, #matches, #ne, #neg, #not, #not_null?, #null?, #or, #order, #sample

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
19
# 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
  @predecessors = [left_expression, right_expression]
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)


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

def simple?
  false
end

#to_s(inner = false) ⇒ Object



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

def to_s(inner=false)
  if inner
    left  = @left_expression.field_alias
    right = @right_expression.field_alias
  else
    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
  end
  "#{left} #{@operator} #{right}"
end