Sha256: ce70fa491703886a7d07567dee6a8b913472d6c02b36ab23798af12ec009498d

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

module CommandLion

  # Raw command-line option API
  module Raw

    @arguments = ARGV

    def self.arguments
      return @arguments unless block_given?
      @arguments.each do |argument|
        yield argument
      end
    end

    def self.arguments=(args)
      @arguments = args
    end

    def self.arguments?
      arguments.size > 0 ? true : false
    end

    def self.index_of(flag)
      arguments.index(flag)
    end

    def self.index_of?(flag)
      index_of(flag) ? true : false
    end

    def self.arguments_to(string, flags)
      return if string.nil?
      return if flags.nil?
      return unless index = index_of(string)
      if block_given?
        arguments.drop(index+1).each do |argument|
          # next if argument == ","
          break if flags.include?(argument)
          yield argument
        end
      else
        args = []
        arguments_to(string, flags) { |arg| args << arg }
        return args
      end
    end

    def self.arguments_to?(flag)
      arguments[arguments.index(flag) + 1] ? true : false
    end
    
    def self.possible_argument_to(string)
      arguments[arguments.index(string) + 1]
    end

    def self.clear!
      @arguments = []
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
command_lion-2.0.1 lib/command_lion/raw.rb
command_lion-2.0.0 lib/command_lion/raw.rb