Sha256: 1083188a9412fa5bcaccbbec038e15eaaa5c34ea6a934e585065307523806a20

Contents?: true

Size: 467 Bytes

Versions: 13

Compression:

Stored size: 467 Bytes

Contents

module ArgsParser
  class Validator
    def validators
      @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

13 entries across 13 versions & 1 rubygems

Version Path
args_parser-0.1.6 lib/args_parser/validator.rb
args_parser-0.1.5 lib/args_parser/validator.rb
args_parser-0.1.4 lib/args_parser/validator.rb
args_parser-0.1.3 lib/args_parser/validator.rb
args_parser-0.1.2 lib/args_parser/validator.rb
args_parser-0.1.1 lib/args_parser/validator.rb
args_parser-0.1.0 lib/args_parser/validator.rb
args_parser-0.0.10 lib/args_parser/validator.rb
args_parser-0.0.9 lib/args_parser/validator.rb
args_parser-0.0.8 lib/args_parser/validator.rb
args_parser-0.0.7 lib/args_parser/validator.rb
args_parser-0.0.6 lib/args_parser/validator.rb
args_parser-0.0.5 lib/args_parser/validator.rb