Class: List

Class | List
In: | optparse.rb
Parent: | Object

Simple option list providing mapping from short and/or long option string to ((<OptionParser::Switch>)), and mapping from acceptable argument to matching pattern and converter pair. Also provides summary feature.

### Methods

accept add_banner append complete each_option new prepend reject search summarize

### Attributes

atype | [R] | Map from acceptable argument types to pattern and converter pairs.
list | [R] | List of all switches and summary string.
long | [R] | Map from long style option switches to actual switch objects.
short | [R] | Map from short style option switches to actual switch objects.

### Public Class methods

new()

Just initializes all instance variables.

[Source]

    # File optparse.rb, line 526
        def initialize
          @atype = {}
          @short = OptionMap.new
          @long = OptionMap.new
          @list = []
        end

### Public Instance methods

accept(t, pat = /.*/, &block)

See OptionParser.accept.

[Source]

    # File optparse.rb, line 536
        def accept(t, pat = /.*/, &block)
          if pat
            pat.respond_to?(:match) or raise TypeError, "has no `match'"
          else
            pat = t if t.respond_to?(:match)
          end
          unless block
            block = pat.method(:convert).to_proc if pat.respond_to?(:convert)
          end
          @atype[t] = [pat, block]
        end

add_banner(to)

[Source]

    # File optparse.rb, line 681
        def add_banner(to)
          list.each do |opt|
            if opt.respond_to?(:add_banner)
              opt.add_banner(to)
            end
          end
          to
        end

append(*args)

OptionParser::List#append(switch, short_opts, long_opts, nolong_opts)

Appends ((|switch|)) at tail of the list, and associates short, long and negated long options.

     :Parameters:
       : ((|switch|))
         ((<OptionParser::Switch>)) instance to be inserted.
       : ((|short_opts|))
         list of short style options.
       : ((|long_opts|))
         list of long style options.
       : ((|nolong_opts|))
         list of long style options with (({"no-"})) prefix.

[Source]

    # File optparse.rb, line 604
        def append(*args)
          update(*args)
          @list.push(args[0])
        end

complete(id, opt, icase = false, *pat, &block)

OptionParser::List#complete(id, opt, *pat, &block)

Searches list ((|id|)) for ((|opt|)) and ((|*pat|)).

     :Parameters:
       : ((|id|))
         searching list.
       : ((|opt|))
         searching key.
       : ((|icase|))
         search case insensitive if true.
       : ((|*pat|))
         optional pattern for completion.
       : (({block}))
         yielded with the found value when succeeded.

[Source]

    # File optparse.rb, line 645
        def complete(id, opt, icase = false, *pat, &block)
          __send__(id).complete(opt, icase, *pat, &block)
        end

each_option(&block)

OptionParser::List#each_option

Iterates for each options.

[Source]

    # File optparse.rb, line 654
        def each_option(&block)
          list.each(&block)
        end

prepend(*args)

OptionParser::List#prepend(switch, short_opts, long_opts, nolong_opts)

Inserts ((|switch|)) at head of the list, and associates short, long and negated long options.

[Source]

    # File optparse.rb, line 585
        def prepend(*args)
          update(*args)
          @list.unshift(args[0])
        end

reject(t)

See OptionParser.reject.

[Source]

    # File optparse.rb, line 551
        def reject(t)
          @atype.delete(t)
        end

search(id, key) {|val| ...}

OptionParser::List#search(id, key) [{block}]

Searches ((|key|)) in ((|id|)) list.

     :Parameters:
       : ((|id|))
         searching list.
       : ((|k|))
         searching key.
       : (({block}))
         yielded with the found value when succeeded.

[Source]

    # File optparse.rb, line 621
        def search(id, key)
          if list = __send__(id)
            val = list.fetch(key) {return nil}
            return val unless block_given?
            yield(val)
          end
        end

summarize(*args) {|""| ...}

OptionParser::List#summarize(*args) {…}

Making summary table, yields the (({block})) with each lines. Each elements of (({@list})) should be able to (({summarize})).

     :Parameters:
       : ((|args|))
         passed to elements#summarize through.
       : (({block}))
         to be passed each lines(without newline).

[Source]

    # File optparse.rb, line 669
        def summarize(*args, &block)
          list.each do |opt|
            if opt.respond_to?(:summarize) # perhaps OptionParser::Switch
              opt.summarize(*args, &block)
            elsif opt.empty?
              yield("")
            else
              opt.each(&block)
            end
          end
        end

[Validate]