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

#convert, #source, #target

Instance Method Summary collapse

Methods inherited from Converter

create, #fail_conversion_type, #initialize

Constructor Details

This class inherits a constructor from Necromancer::Converter

Instance Method Details

#call(value, options = {}) ⇒ Object

Convert integer to boolean

Examples:

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


53
54
55
56
57
58
59
60
# File 'lib/necromancer/converters/boolean.rb', line 53

def call(value, options = {})
  strict = options.fetch(:strict, config.strict)
  begin
    !value.zero?
  rescue
    strict ? fail_conversion_type(value) : value
  end
end