Class: Necromancer::BooleanConverters::StringToBooleanConverter

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

Overview

An object that converts a String 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 value to boolean type including range of strings

other values coerced to false are:
  0, f, F, FALSE, false, False, n, N, NO,  no,  No, off, OFF

Examples:

converter.call("True") # => true

other values converted to true are:
  1, t, T, TRUE,  true,  True,  y, Y, YES, yes, Yes, on, ON
converter.call("False") # => false

Parameters:

  • value (Object)


32
33
34
35
36
37
38
# File 'lib/necromancer/converters/boolean.rb', line 32

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
end