Sha256: 644551154f5cc5b1096ca44698b9b98f401d185f0c664b8c35a1be1aa421148b

Contents?: true

Size: 685 Bytes

Versions: 2

Compression:

Stored size: 685 Bytes

Contents

module Clamp
  class Option

    module Parsing

      protected

      def parse_options
        while arguments.first =~ /^-/

          switch = arguments.shift
          break if switch == "--"

          option = find_option(switch)
          value = option.extract_value(switch, arguments)

          begin
            send("#{option.attribute_name}=", value)
          rescue ArgumentError => e
            signal_usage_error "option '#{switch}': #{e.message}"
          end

        end
      end

      private

      def find_option(switch)
        self.class.find_option(switch) || 
        signal_usage_error("Unrecognised option '#{switch}'")
      end

    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
clamp-0.1.0 lib/clamp/option/parsing.rb
clamp-0.0.9 lib/clamp/option/parsing.rb