Class: Musa::GenerativeGrammar::Implementation::BlockNode Private

Inherits:
Node
  • Object
show all
Defined in:
lib/musa-dsl/generative/generative-grammar.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Node with dynamic content generated by block.

Executes block at generation time to produce content. Block receives parent elements and attributes.

Instance Method Summary collapse

Constructor Details

#initialize(attributes) {|parent, attributes| ... } ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • attributes (Hash)

    node attributes

Yields:

  • (parent, attributes)

    block to generate content



502
503
504
505
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 502

def initialize(attributes, &block)
  @attributes = attributes
  @block = block
end

Instance Method Details

#_options(parent: nil, &condition) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 508

def _options(parent: nil, &condition)
  parent ||= []

  element = @block.call(parent, @attributes)
  element = OptionElement.new(element, @attributes) unless element.is_a?(OptionElement)

  if block_given?
    if yield(parent + [element], @attributes)
      [[element]]
    else
      []
    end
  else
    [[element]]
  end
end