Method: ParamChecker.check_boolean

Defined in:
lib/param_checker.rb

.check_boolean(param, default, options = {}) ⇒ Object

Check a parameter string if it represents a valid boolean and return its boolean value.

  • param: the string parameter to check

  • default: the default boolean to return if the check fails

  • options: a hash of options:

    • true: an array of string representations of true (by default “1” and “true”)

    • false: an array of string representations of false (by default “0” and “false”)



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/param_checker.rb', line 81

def check_boolean(param, default, options = {})
  true_values = (options[:true] ? options[:true] : ["1", "true"])
  false_values = (options[:false] ? options[:false] : ["0", "false"])
  if (true_values.include?(param))
    true
  elsif (false_values.include?(param))
    false
  else
    default
  end
end