Method: Musa::GenerativeGrammar::Implementation::Node#limit

Defined in:
lib/musa-dsl/generative/generative-grammar.rb

#limit(attribute = nil, after_collect_operation = nil, comparison_method = nil, comparison_value = nil) {|option| ... } ⇒ ConditionNode

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.

Limits generated options by condition.

Filters options to only those satisfying the given condition. Can use simplified arguments or custom block.

Examples:

Block form

grammar = (a | b).repeat.limit { |o|
  o.collect { |e| e.attributes[:size] }.sum == 3
}

Simplified form

grammar = (a | b).repeat.limit(:size, :sum, :==, 3)

Parameters:

  • attribute (Symbol, nil) (defaults to: nil)

    attribute to check (simplified form)

  • after_collect_operation (Symbol, nil) (defaults to: nil)

    operation on collected values

  • comparison_method (Symbol, nil) (defaults to: nil)

    comparison method to apply

  • comparison_value (Object, nil) (defaults to: nil)

    value to compare against

Yield Parameters:

Yield Returns:

  • (Boolean)

    true if option should be included

Returns:

Raises:

  • (ArgumentError)

    if both simplified arguments and block given



270
271
272
273
274
275
276
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 270

def limit(attribute = nil, after_collect_operation = nil, comparison_method = nil, comparison_value = nil, &block)
  raise ArgumentError, 'Cannot use simplified arguments and yield block at the same time' if (attribute || after_collect_operation || comparison_method || comparison_value) && @block

  block ||= generate_simple_condition_block(attribute, after_collect_operation, comparison_method, comparison_value)

  ConditionNode.new(self, &block)
end