Class: TermUtils::AP::Level

Inherits:
Element
  • Object
show all
Defined in:
lib/term_utils/ap/level.rb

Overview

Represents an argument list subset. It must lead with a Flag. It has its own syntax.

Instance Attribute Summary collapse

Attributes inherited from Element

#flags, #id, #max_occurs, #min_occurs

Instance Method Summary collapse

Methods inherited from Element

#define_flag, #flagged?, #multiple_occurs?, #occur_bounded?

Constructor Details

#initialize(opts = {}) ⇒ Level

Constructs a new Level.

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :id (Symbol)
  • :min_occurs (Integer)

    Default value is `0`.

  • :max_occurs (Integer)

    Default value is `1`.



30
31
32
33
34
35
36
# File 'lib/term_utils/ap/level.rb', line 30

def initialize(opts = {})
  @id = opts.fetch(:id, nil)
  @min_occurs = opts.fetch(:min_occurs, 0)
  @max_occurs = opts.fetch(:max_occurs, 1)
  @flags = []
  @syntax = TermUtils::AP::Syntax.new
end

Instance Attribute Details

#syntaxTermUtils::AP::Syntax



24
25
26
# File 'lib/term_utils/ap/level.rb', line 24

def syntax
  @syntax
end

Instance Method Details

#define_syntax(&block) ⇒ TermUtils::AP::Syntax

Defines the syntax.



51
52
53
54
# File 'lib/term_utils/ap/level.rb', line 51

def define_syntax(&block)
  block.call(@syntax) if block
  @syntax
end

#finalize!(opts = {}) ⇒ nil

Finalizes this one. Internal use.

Returns:

  • (nil)

Raises:



44
45
46
47
48
# File 'lib/term_utils/ap/level.rb', line 44

def finalize!(opts = {})
  super
  raise TermUtils::AP::SyntaxError, "level must contain at least one flag" if @flags.empty?
  @syntax.finalize!(opts)
end

#initialize_dup(other) ⇒ Object

For dup method.



38
39
40
41
# File 'lib/term_utils/ap/level.rb', line 38

def initialize_dup(other)
  @syntax = other.syntax.dup
  super
end