Sha256: 87b25226e454c6393205f338d423a8a69f3ae292b60dab1a84caeb736e5c108a

Contents?: true

Size: 881 Bytes

Versions: 1

Compression:

Stored size: 881 Bytes

Contents

module ParamChecker
  module HashExt

    def check(type, key, default, options = {})
      value = nil
      if key.class == Array
        value = self
        key.each do |k|
          value = value[k]
          break if value.nil?
        end
      else # String || Symbol
        value = self[key]
      end

      if value.nil?
        default
      else
        case type
        when :integer, :i
          ParamChecker.check_integer(value, default, options)
        when :float, :f
          ParamChecker.check_float(value, default, options)
        when :string, :s
          ParamChecker.check_string(value, default, options)
        when :symbol, :sym
          ParamChecker.check_symbol(value, default, options)
        when :boolean, :b
          ParamChecker.check_boolean(value, default, options)
        else
          raise
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
param_checker-0.3.0 lib/param_checker/hash_ext.rb