Class: CallCenter::ConditionalStack

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

Defined Under Namespace

Classes: Conditional, Evaluator, IfConditional, UnlessConditional

Instance Method Summary collapse

Constructor Details

#initializeConditionalStack

Returns a new instance of ConditionalStack


3
4
5
# File 'lib/call_center/conditional_stack.rb', line 3

def initialize
  @stack = []
end

Instance Method Details

#<<(obj) ⇒ Object


7
8
9
# File 'lib/call_center/conditional_stack.rb', line 7

def <<(obj)
  @stack << obj
end

#any?Boolean

Returns:

  • (Boolean)

15
16
17
# File 'lib/call_center/conditional_stack.rb', line 15

def any?
  @stack.any?
end

#inject(options) ⇒ Object


19
20
21
22
23
24
25
26
27
28
# File 'lib/call_center/conditional_stack.rb', line 19

def inject(options)
  current_stack = @stack.dup
  current_stack << IfConditional.new(options[:if]) if options[:if]

  evaluator = Evaluator.new(current_stack) { |model|
    current_stack.map { |conditional| conditional.evaluate(model) }.all?
  }

  options.merge(:if => evaluator)
end

#popObject


11
12
13
# File 'lib/call_center/conditional_stack.rb', line 11

def pop
  @stack.pop
end