Class: Fabulator::Core::Actions::Choose

Inherits:
Structural
  • Object
show all
Defined in:
lib/fabulator/core/actions/choose.rb

Instance Method Summary collapse

Methods inherited from Structural

#accepts_structural?, accepts_structural?, #compile_xml, contained_in, contains, element, #initialize, structurals

Constructor Details

This class inherits a constructor from Fabulator::Structural

Instance Method Details

#run(context, autovivify = false) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fabulator/core/actions/choose.rb', line 11

def run(context, autovivify = false)
  @context.with(context) do |ctx|
    @choices.each do |c|
      if c.run_test(ctx)
        return c.run(ctx)
      end
    end
    return @default.first.run(ctx) unless @default.empty?
    return []
  end
end