Module: Trxl::BinaryOperatorSupport

Included in:
NilAcceptingOperator, NilRejectingOperator
Defined in:
lib/trxl/trxl.rb

Instance Method Summary collapse

Instance Method Details

#apply(a, b) ⇒ Object



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/trxl/trxl.rb', line 191

def apply(a, b)
  if a.nil?
    if b.nil?
      if nils_allowed?
        perform_apply(a, b)
      else
        raise InvalidArgumentException, "Both operands MUST NOT be NULL"
      end
    else
      if lhs_nil_allowed?
        perform_apply(a, b)
      else
        raise InvalidArgumentException, "LHS operand MUST NOT be NULL"
      end
    end
  else
    if b.nil?
      if rhs_nil_allowed?
        perform_apply(a, b)
      else
        raise InvalidArgumentException, "RHS operand MUST NOT be NULL"
      end
    else
      perform_apply(a, b)
    end
  end
end

#lhs_nil_allowed?Boolean

Returns:

  • (Boolean)

Raises:



179
180
181
# File 'lib/trxl/trxl.rb', line 179

def lhs_nil_allowed?
  raise InternalError, "Implement BinaryOperaterSupport#lhs_nil_allowed?"
end

#nils_allowed?Boolean

Returns:

  • (Boolean)


187
188
189
# File 'lib/trxl/trxl.rb', line 187

def nils_allowed?
  lhs_nil_allowed? && rhs_nil_allowed?
end

#perform_apply(a, b) ⇒ Object



219
220
221
222
223
224
225
226
227
# File 'lib/trxl/trxl.rb', line 219

def perform_apply(a, b)
  if a.respond_to?(ruby_operator)
    a.send(ruby_operator, b)
  else
    _a = a ? (a.is_a?(String) ? "'#{a}'" : a) : false
    _b = b ? (b.is_a?(String) ? "'#{b}'" : b) : false
    eval "#{_a} #{ruby_operator} #{_b}"
  end
end

#rhs_nil_allowed?Boolean

Returns:

  • (Boolean)

Raises:



183
184
185
# File 'lib/trxl/trxl.rb', line 183

def rhs_nil_allowed?
  raise InternalError, "Implement BinaryOperaterSupport#rhs_nil_allowed?"
end

#ruby_operatorObject



229
230
231
# File 'lib/trxl/trxl.rb', line 229

def ruby_operator
  text_value
end