Sha256: 56bfc451b3279fe34748fa303c0b4812f11fbe783ef741e180dc17f51430d5de

Contents?: true

Size: 1.35 KB

Versions: 7

Compression:

Stored size: 1.35 KB

Contents

module ::Af::OptionParser
  class OptionType
    attr_reader :name,
                :short_name,
                :argument_note,
                :evaluate_method,
                :handler_method

    @@types = []

    def initialize(name, short_name, argument_note, evaluate_method, handler_method)
      @name = name
      @short_name = short_name
      @argument_note = argument_note
      @evaluate_method = evaluate_method
      @handler_method = handler_method
      @@types << self
    end

    #----------------------
    # *** Class Methods ***
    #++++++++++++++++++++++

    def self.types
      return @@types
    end

    def self.valid_option_type_names
      return types.map(&:short_name)
    end

    def self.find_by_value(value)
      return types.find{ |t| t.handle?(value) }
    end

    def self.find_by_short_name(short_name)
      return types.find{ |t| t.short_name == short_name }
    end

    #-------------------------
    # *** Instance Methods ***
    #+++++++++++++++++++++++++

    def evaluate_argument(argument, option)
      if @evaluate_method.is_a? Symbol
        return argument.send(@evaluate_method)
      end
      return @evaluate_method.call(argument, option)
    end

    def handle?(value)
      if @handler_method.is_a? Class
        return value.is_a? @handler_method
      end
      return @handler_method.call(value)
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fiksu-af-1.1.6 lib/fiksu-af/option_parser/option_type.rb
fiksu-af-1.1.5 lib/fiksu-af/option_parser/option_type.rb
fiksu-af-1.1.4 lib/fiksu-af/option_parser/option_type.rb
fiksu-af-1.1.3 lib/fiksu-af/option_parser/option_type.rb
fiksu-af-1.1.2 lib/fiksu-af/option_parser/option_type.rb
fiksu-af-1.1.1 lib/fiksu-af/option_parser/option_type.rb
fiksu-af-1.1.0 lib/fiksu-af/option_parser/option_type.rb