Class: Babl::Operators::Switch::SwitchNode

Inherits:
Object
  • Object
show all
Defined in:
lib/babl/operators/switch.rb

Instance Method Summary collapse

Constructor Details

#initialize(nodes) ⇒ SwitchNode

Returns a new instance of SwitchNode.



40
41
42
# File 'lib/babl/operators/switch.rb', line 40

def initialize(nodes)
    @nodes = nodes
end

Instance Method Details

#dependenciesObject



44
45
46
47
# File 'lib/babl/operators/switch.rb', line 44

def dependencies
    (nodes.values + nodes.keys).map(&:dependencies)
        .reduce({}) { |a, b| Babl::Utils::Hash.deep_merge(a, b) }
end

#documentationObject



54
55
56
57
58
# File 'lib/babl/operators/switch.rb', line 54

def documentation
    (nodes.values).map(&:documentation).each_with_index.map { |doc, idx|
        [:"Case #{idx + 1}", doc]
    }.to_h
end

#pinned_dependenciesObject



49
50
51
52
# File 'lib/babl/operators/switch.rb', line 49

def pinned_dependencies
    (nodes.values + nodes.keys).map(&:pinned_dependencies)
        .reduce({}) { |a, b| Babl::Utils::Hash.deep_merge(a, b) }
end

#render(ctx) ⇒ Object



60
61
62
63
# File 'lib/babl/operators/switch.rb', line 60

def render(ctx)
    nodes.each { |cond, value| return value.render(ctx) if cond.render(ctx) }
    raise Babl::RenderingError, 'A least one switch() condition must be taken'
end