Sha256: 8701f59f8db3f43eb0f0a289531d31910df457bc1df38ab758d1820f479958db

Contents?: true

Size: 494 Bytes

Versions: 1

Compression:

Stored size: 494 Bytes

Contents

module ArgsParser
  class Validator

    attr_reader :validators

    def initialize
      @validators = []
    end

    def add(name, message, validator)
      name = name.to_sym if name
      validators.push({:name => name, :message => message, :validator => validator})
    end

    def validate(name, value)
      validators.each do |f|
        if !f[:name] or f[:name] == name
          return f[:message] unless f[:validator].call(value)
        end
      end
      nil
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
args_parser-0.2.0 lib/args_parser/validator.rb