Files

Class/Module Index [+]

Quicksearch

God::Conditions::Complex

Constants

AND
NOT
OR

Public Class Methods

new() click to toggle source
# File lib/god/conditions/complex.rb, line 9
def initialize()
  super

  @oper_stack = []
  @op_stack = []

  @this = nil
end

Public Instance Methods

and(kind) click to toggle source
# File lib/god/conditions/complex.rb, line 38
def and(kind)
  oper = new_oper(kind, 0x1)
  yield oper if block_given?
end
and_not(kind) click to toggle source
# File lib/god/conditions/complex.rb, line 43
def and_not(kind)
  oper = new_oper(kind, 0x5)
  yield oper if block_given?
end
new_oper(kind, op) click to toggle source
# File lib/god/conditions/complex.rb, line 26
def new_oper(kind, op)
  oper = Condition.generate(kind, self.watch)
  @oper_stack.push(oper)
  @op_stack.push(op)
  oper
end
or(kind) click to toggle source
# File lib/god/conditions/complex.rb, line 48
def or(kind)
  oper = new_oper(kind, 0x2)
  yield oper if block_given?
end
or_not(kind) click to toggle source
# File lib/god/conditions/complex.rb, line 53
def or_not(kind)
  oper = new_oper(kind, 0x6)
  yield oper if block_given?
end
prepare() click to toggle source
# File lib/god/conditions/complex.rb, line 22
def prepare
  @oper_stack.each { |oper| oper.prepare }
end
test() click to toggle source
# File lib/god/conditions/complex.rb, line 58
def test
  if @this.nil?
    # Although this() makes sense semantically and therefore
    # encourages easy-to-read conditions, being able to omit it
    # allows for more DRY code in some cases, so we deal with a
    # nil @this here by initially setting res to true or false,
    # depending on whether the first operator used is AND or OR
    # respectively.
    if 0 < @op_stack[0] & AND
      res = true
    else
      res = false
    end
  else
    res = @this.test
  end

  @op_stack.each do |op|
    cond = @oper_stack.shift
    eval "res " + ((0 < op & AND) ? "&&" : "||") + "= " + ((0 < op & NOT) ? "!" : "") + "cond.test"
    @oper_stack.push cond
  end

  res
end
this(kind) click to toggle source
# File lib/god/conditions/complex.rb, line 33
def this(kind)
  @this = Condition.generate(kind, self.watch)
  yield @this if block_given?
end
valid?() click to toggle source
# File lib/god/conditions/complex.rb, line 18
def valid?
  @oper_stack.inject(true) { |acc, oper| acc & oper.valid? }
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.