lib/necromancer/converters/boolean.rb in necromancer-0.6.0 vs lib/necromancer/converters/boolean.rb in necromancer-0.7.0
- old
+ new
@@ -27,12 +27,11 @@
#
# other values coerced to false are:
# 0, f, F, FALSE, false, False, n, N, NO, no, No, off, OFF
#
# @api public
- def call(value, options = {})
- strict = options.fetch(:strict, config.strict)
+ def call(value, strict: config.strict)
case value.to_s
when TRUE_MATCHER then true
when FALSE_MATCHER then false
else strict ? raise_conversion_type(value) : value
end
@@ -48,17 +47,14 @@
#
# @example
# converter.call(0) # => false
#
# @api public
- def call(value, options = {})
- strict = options.fetch(:strict, config.strict)
- begin
- !value.zero?
- rescue
- strict ? raise_conversion_type(value) : value
- end
+ def call(value, strict: config.strict)
+ !value.zero?
+ rescue StandardError
+ strict ? raise_conversion_type(value) : value
end
end
# An object that converts a Boolean to an Integer
class BooleanToIntegerConverter < Converter
@@ -69,23 +65,26 @@
#
# @example
# converter.call(false) # => 0
#
# @api public
- def call(value, options = {})
- strict = options.fetch(:strict, config.strict)
+ def call(value, strict: config.strict)
if %w[TrueClass FalseClass].include?(value.class.name)
value ? 1 : 0
else
strict ? raise_conversion_type(value) : value
end
end
end
def self.load(conversions)
- conversions.register StringToBooleanConverter.new(:string, :boolean)
- conversions.register IntegerToBooleanConverter.new(:integer, :boolean)
- conversions.register BooleanToIntegerConverter.new(:boolean, :integer)
- conversions.register NullConverter.new(:boolean, :boolean)
+ [
+ StringToBooleanConverter.new(:string, :boolean),
+ IntegerToBooleanConverter.new(:integer, :boolean),
+ BooleanToIntegerConverter.new(:boolean, :integer),
+ NullConverter.new(:boolean, :boolean)
+ ].each do |converter|
+ conversions.register converter
+ end
end
end # BooleanConverters
end # Necromancer