Sha256: db5e647942285c7f98ee28fe6dfa7a47f45d4a07c70751c261db81fdbdbd252e
Contents?: true
Size: 628 Bytes
Versions: 1
Compression:
Stored size: 628 Bytes
Contents
# frozen_string_literal: true module HoneyFormat # String values considered truthy TRUTHY = Set.new(%w[t T 1 y Y true TRUE]).freeze # String values considered falsy FALSY = Set.new(%w[f F 0 n N false FALSE]).freeze # Tries to convert value boolean to, returns nil if it can't convert ConvertBoolean = proc do |v| if TRUTHY.include?(v) true elsif FALSY.include?(v) false end end # Convert to boolean or raise error StrictConvertBoolean = proc do |v| ConvertBoolean.call(v).tap do |value| raise(ArgumentError, "can't convert #{v} to boolean") if value.nil? end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
honey_format-0.17.0 | lib/honey_format/converters/convert_boolean.rb |