Module: ActiveMetadata::Helpers

Included in:
Base::InstanceMethods
Defined in:
lib/active_metadata/helpers.rb

Instance Method Summary collapse

Instance Method Details

#to_bool(str) ⇒ Object

Raises:

  • (ArgumentError)


3
4
5
6
7
# File 'lib/active_metadata/helpers.rb', line 3

def to_bool str
  return true if str == true || str =~ (/(true|t|yes|y|1)$/i)
  return false if str == false || str.blank? || str =~ (/(false|f|no|n|0)$/i)
  raise ArgumentError.new("invalid value for Boolean: \"#{str}\"")
end