Class: Necromancer::BooleanConverters::IntegerToBooleanConverter

Inherits:
Converter
  • Object
show all
Defined in:
lib/necromancer/converters/boolean.rb

Overview

An object that converts an Integer to a Boolean

Instance Attribute Summary

Attributes inherited from Converter

#config, #convert, #source, #target

Instance Method Summary collapse

Methods inherited from Converter

create, #initialize, #raise_conversion_type

Constructor Details

This class inherits a constructor from Necromancer::Converter

Instance Method Details

#call(value, strict: config.strict) ⇒ Object

Convert integer to boolean

Examples:

converter.call(1)  # => true
converter.call(0)  # => false


52
53
54
55
56
# File 'lib/necromancer/converters/boolean.rb', line 52

def call(value, strict: config.strict)
  !value.zero?
rescue StandardError
  strict ? raise_conversion_type(value) : value
end