class Leafy::Converter::BoolConverter

Public Instance Methods

dump(value) click to toggle source
# File lib/leafy/converter/bool_converter.rb, line 6
def dump(value)
  target = value
  target = load(target) unless value.is_a?(TrueClass) || value.is_a?(FalseClass)

  target ? "1" : "0"
end
load(value) click to toggle source
# File lib/leafy/converter/bool_converter.rb, line 13
def load(value)
  return if value.nil?

  target = value.respond_to?(:downcase) ? (value.downcase rescue nil) : value
  return true if ["1", "true", "t", 1, "yes", "y", true].include?(target)
  return false if ["0", "false", "f", 0, "no", "n", false].include?(target)

  raise(ArgumentError, "can't parse value to bool: #{value}")
end