Class: Babl::Operators::Switch::SwitchNode
- Inherits:
-
Object
- Object
- Babl::Operators::Switch::SwitchNode
- Defined in:
- lib/babl/operators/switch.rb
Instance Method Summary collapse
- #dependencies ⇒ Object
- #documentation ⇒ Object
-
#initialize(nodes) ⇒ SwitchNode
constructor
A new instance of SwitchNode.
- #pinned_dependencies ⇒ Object
- #render(ctx) ⇒ Object
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
#dependencies ⇒ Object
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 |
#documentation ⇒ Object
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_dependencies ⇒ Object
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 |