Class: SQLConditional::BasicCond

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

Overview

Internal class which represents a basic logical operation.

Constant Summary collapse

LHS =
-1
MIDDLE =
0
RHS =
1

Instance Method Summary collapse

Constructor Details

#initialize(operator, type, *objects) ⇒ BasicCond

Returns a new instance of BasicCond.



168
169
170
171
# File 'lib/sqlconditional.rb', line 168

def initialize ( operator, type, *objects )
    @operator, @type, @objects = operator.to_s, type, objects
    @string = nil
end

Instance Method Details

#to_sObject



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/sqlconditional.rb', line 173

def to_s
    return @string  if @string
    @string = " "
    if @objects.empty?
        @string += " " + @operator + " "
    else
        case @type
            when LHS 
                @string = @operator + " " + @objects[0].to_s
            when RHS
                @string = @objects[0].to_s + " " + @operator
            when MIDDLE 
                @string = @objects.empty?  ?  " " + @operator + " "  
                                           :  @objects.join( " " + @operator + " " )
            else
                raise NameError, ERR_UNKNOWN_OPERATOR_TYPE
        end
    end
end