Sha256: a8e711491c1a047005f8e166b569b58908c8aa0d0caf98f79e0fb51fa88a44e0

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

require 'rprogram/argument'

module RProgram
  class NonOption < Argument

    # Name of the argument(s)
    attr_reader :name

    # Can the argument be specified multiple times
    attr_reader :multiple

    #
    # Creates a new NonOption object.
    #
    # @param [Hash] options
    #   Additional options.
    #
    # @option options [Symbol] :name
    #   The name of the non-option.
    #
    # @option options [true, false] :leading (true)
    #   Implies the non-option is a leading non-option.
    #
    # @option options [false, true] :tailing (false)
    #   Implies the non-option is a tailing non-option.
    #
    # @option options [false, true] :multiple (false)
    #   Implies the non-option maybe given an Array of values.
    #
    def initialize(options={})
      @name = options[:name]

      @tailing = if    options[:leading] then !options[:leading]
                 elsif options[:tailing] then options[:tailing]
                 else                         true
                 end

      @multiple = (options[:multiple] || false)
    end

    #
    # Determines whether the non-option's arguments are tailing.
    #
    # @return [true, false]
    #   Specifies whether the non-option's arguments are tailing.
    #
    def tailing?
      @tailing == true
    end

    #
    # Determines whether the non-option's arguments are leading.
    #
    # @return [true, false]
    #   Specifies whether the non-option's arguments are leading.
    #
    def leading?
      !(@tailing)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rprogram-0.3.2 lib/rprogram/non_option.rb