Module: Kernel

Defined in:
lib/bright/helpers/boolean_parser_helper.rb

Instance Method Summary collapse

Instance Method Details

#Boolean(string) ⇒ Object

Raises:

  • (ArgumentError)


2
3
4
5
6
# File 'lib/bright/helpers/boolean_parser_helper.rb', line 2

def Boolean(string)
  return true if string == true || string =~ /^true$/i || string == "1" || string == 1 || string.to_s.downcase == "yes"
  return false if string == false || string.nil? || string =~ /^false$/i || string == "0" || string == 0 || string.to_s.downcase == "no" || string.blank?
  raise ArgumentError.new("invalid value for Boolean: \"#{string}\"")
end