Sha256: d6a76707cd161830d0ccde1fc16745873bc5e1ae000c91864e4bc99d72e2a708

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

module RProgram
  class NonOption

    # Name of the argument(s)
    attr_reader :name

    # Is the argument a leading argument(s)
    attr_reader :leading

    # Is the argument a tailing argument(s)
    attr_reader :tailing

    # Can the argument be specified multiple times
    attr_reader :multiple

    #
    # Creates a new NonOption object with the specified _options_.
    #
    # _options_ may contain the following keys:
    # <tt>:name</tt>:: The name of the non-option.
    # <tt>:leading</tt>:: Implies the non-option is a leading non-option.
    #                     Defaults to +false+, if not given.
    # <tt>:tailing</tt>:: Implies the non-option is a tailing non-option.
    #                     Defaults to +true+, if not given.
    # <tt>:multiple</tt>:: Implies the non-option maybe given an Array
    #                      of values. Defaults to +false+, if not given.
    #
    def initialize(options={})
      @name = options[:name]

      @leading = options[:leading] || false
      @tailing = options[:tailing] || true
      @multiple = options[:multiple] || false
    end

    #
    # Returns an +Array+ of the arguments for the non-option with the
    # specified _value_.
    #
    def arguments(value)
      return [] if (value==nil || value==false)

      if value.kind_of?(Hash)
        return value.map { |name,value| "#{name}=#{value}" }
      elsif value.kind_of?(Array)
        if @multiple
          return value.compact
        else
          return value.join
        end
      else
        return [value]
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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