Sha256: 0dc0009deec1a07d8257bc3f34b278b7f40cb54f34377c90b17154cfe47430ab

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 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 a Flag.
    class Flag
      # @return [String]
      attr_accessor :label
      # @return [Symbol] `:anchor`, `:long`, `:short`.
      attr_accessor :flavor
      # Constructs a new Flag.
      # @param opts [Hash]
      # @option opts [String] :label
      # @option opts [Symbol] :flavor `:anchor`, `:long`, `:short`.
      def initialize(opts = {})
        @label = opts.fetch(:label, nil)
        @flavor = opts.fetch(:flavor, nil)
      end
      # Returns the string representation of this one.
      # @return [String]
      def to_s
        case @flavor
        when :anchor
          @label
        when :long
          "--%s" % @label
        when :short
          "-%s" % @label
        end
      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/flag.rb
term_utils-0.3.1 lib/term_utils/ap/flag.rb
term_utils-0.3.0 lib/term_utils/ap/flag.rb