class Cql::Model::Query::ComparisonExpression

@TODO docs

Constants

OPERATORS

Operators allowed in a where-clause lambda

TYPECASTS

Methods used to escape CQL column names that aren’t valid CQL identifiers

Public Class Methods

new(*params, &block) click to toggle source

@TODO docs

# File lib/cql/model/query/comparison_expression.rb, line 37
def initialize(*params, &block)
  @left     = nil
  @operator = nil
  @right    = nil

  instance_exec(*params, &block) if block
end

Public Instance Methods

inspect() click to toggle source

@TODO docs

# File lib/cql/model/query/comparison_expression.rb, line 51
def inspect
  __build__
end
method_missing(token, *args) click to toggle source

@TODO docs

# File lib/cql/model/query/comparison_expression.rb, line 70
def method_missing(token, *args)
  __apply__(token, args)
end
to_s() click to toggle source

@TODO docs

# File lib/cql/model/query/comparison_expression.rb, line 46
def to_s
  __build__
end

Private Instance Methods

__apply__(token, args) click to toggle source

@TODO docs

# File lib/cql/model/query/comparison_expression.rb, line 77
def __apply__(token, args)
  if @left.nil?
    if args.empty?
      # A well-behaved CQL identifier (column name that is a valid Ruby method name)
      @left = token
    elsif args.length == 1
      # A CQL typecast (column name that is an integer, float, etc and must be wrapped in a decorator)
      @left = args.first
    else
      ::Kernel.raise ::Cql::Model::SyntaxError.new(
                       "Unacceptable token '#{token}'; expected a CQL identifier or typecast")
    end
  elsif @operator.nil?
    # Looking for an operator + right operand
    if OPERATORS.keys.include?(token)
      @operator = token

      if (args.size > 1) || (token == :in)
        @right = args
      else
        @right = args.first
      end
    else
      ::Kernel.raise ::Cql::Model::SyntaxError.new(
                       "Unacceptable token '#{token}'; expected a CQL-compatible operator")
    end
  else
    ::Kernel.raise ::Cql::Model::SyntaxError.new(
                     "Unacceptable token '#{token}'; the expression is " +
                       "already complete")
  end

  self
end
__build__() click to toggle source

@TODO docs

# File lib/cql/model/query/comparison_expression.rb, line 113
def __build__
  if @left.nil? || @operator.nil? || @right.nil?
    ::Kernel.raise ::Cql::Model::SyntaxError.new(
                     "Cannot build a CQL expression; the Ruby expression is incomplete " +
                       "(#{@left.inspect}, #{@operator.inspect}, #{@right.inspect})")
  else
    left  = ::Cql::Model::Query.cql_identifier(@left)
    op    = OPERATORS[@operator]
    right = ::Cql::Model::Query.cql_value(@right)
    "#{left} #{op} #{right}"
  end
end