Sha256: 7f1adc5a6bc031b73648a8e57750afa292f643e6b1a9800fd822885bed7ff3fb
Contents?: true
Size: 830 Bytes
Versions: 10
Compression:
Stored size: 830 Bytes
Contents
# Represents a plain old boolean type. TBD: can be nil? # require_relative '../exceptions' module Attributor class Boolean include Type def self.valid_type?(value) value == true || value == false end def self.example(context=nil, options: {}) [true, false].sample end def self.load(value,context=Attributor::DEFAULT_ROOT_CONTEXT, **options) return nil if value.nil? raise CoercionError, context: context, from: value.class, to: self, value: value if value.is_a?(::Float) return false if [ false, 'false', 'FALSE', '0', 0, 'f', 'F' ].include?(value) return true if [ true, 'true', 'TRUE', '1', 1, 't', 'T' ].include?(value) raise CoercionError, context: context, from: value.class, to: self end def self.family 'boolean' end end end
Version data entries
10 entries across 10 versions & 1 rubygems