class Necromancer::BooleanConverters::BooleanToIntegerConverter

An object that converts a Boolean to an Integer

Public Instance Methods

call(value, options = {}) click to toggle source

Convert boolean to integer

@example

converter.call(true)   # => 1

@example

converter.call(false)  # => 0

@api public

# File lib/necromancer/converters/boolean.rb, line 73
def call(value, options = {})
  strict = options.fetch(:strict, config.strict)
  if ['TrueClass', 'FalseClass'].include?(value.class.name)
    value ? 1 : 0
  else
    strict ? fail_conversion_type(value) : value
  end
end