Module: Veritas::Optimizer::Function::Util

Defined in:
lib/veritas/optimizer/function.rb

Overview

Utility methods for Function optimization

Class Method Summary collapse

Class Method Details

.attribute?(operand) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Test if the operand is an attribute

Returns:

  • (Boolean)


52
53
54
# File 'lib/veritas/optimizer/function.rb', line 52

def self.attribute?(operand)
  operand.kind_of?(Attribute)
end

.constant?(operand) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Test if the operand is a constant

Returns:

  • (Boolean)


43
44
45
# File 'lib/veritas/optimizer/function.rb', line 43

def self.constant?(operand)
  ! (operand.nil? || operand.respond_to?(:call))
end

.max(operand) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the maximum value for the operand

Returns:

  • (Object)


75
76
77
78
79
80
81
82
# File 'lib/veritas/optimizer/function.rb', line 75

def self.max(operand)
  case operand
  when Attribute::String  then operand.max_length
  when Attribute::Numeric then operand.range.last
  else
    operand
  end
end

.min(operand) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the minimum value for the operand

Returns:

  • (Object)


61
62
63
64
65
66
67
68
# File 'lib/veritas/optimizer/function.rb', line 61

def self.min(operand)
  case operand
  when Attribute::String  then operand.min_length
  when Attribute::Numeric then operand.range.first
  else
    operand
  end
end