Class: Leafy::Converter::BoolConverter
- Inherits:
-
Object
- Object
- Leafy::Converter::BoolConverter
- Defined in:
- lib/leafy/converter/bool_converter.rb
Instance Method Summary collapse
Instance Method Details
#dump(value) ⇒ Object
6 7 8 9 10 11 |
# 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) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# 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 |