Sha256: a8a16685beb0c3b32a6a81e3ac11282400722a716182ea67a8dd83e54c4fece1

Contents?: true

Size: 1.88 KB

Versions: 3

Compression:

Stored size: 1.88 KB

Contents

# frozen-string-literal: true
#
# Copyright (C) 2019 Thomas Baron
#
# This file is part of term_utils.
#
# term_utils is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# term_utils is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with term_utils.  If not, see <https://www.gnu.org/licenses/>.
module TermUtils
  module AP
    # Represents an argument list subset. It must lead with a Flag. It has its
    # own syntax.
    class Level < TermUtils::AP::Element
      # @return [TermUtils::AP::Syntax]
      attr_accessor :syntax
      # Constructs a new Level.
      # @param opts [Hash]
      # @option opts [Symbol] :id
      # @option opts [Integer] :min_occurs Default value is `0`.
      # @option opts [Integer] :max_occurs Default value is `1`.
      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
      # For dup method.
      def initialize_dup(other)
        @syntax = other.syntax.dup
        super
      end
      # Finalizes this one. Internal use.
      # @return [nil]
      def finalize!(opts = {})
        super
        raise TermUtils::AP::SyntaxError, "level must contain at least one flag" if @flags.empty?
        @syntax.finalize!(opts)
      end
      # Defines the syntax.
      # @return [TermUtils::AP::Syntax]
      def define_syntax(&block)
        block.call(@syntax) if block
        @syntax
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
term_utils-0.3.2 lib/term_utils/ap/level.rb
term_utils-0.3.1 lib/term_utils/ap/level.rb
term_utils-0.3.0 lib/term_utils/ap/level.rb