Class: StrongCSV::Types::Boolean

Inherits:
Base
  • Object
show all
Defined in:
lib/strong_csv/types/boolean.rb

Overview

Boolean type

Instance Method Summary collapse

Instance Method Details

#cast(value) ⇒ ValueResult

Parameters:

  • value (Object)

    Value to be casted to Boolean

Returns:



13
14
15
16
17
18
19
20
21
# File 'lib/strong_csv/types/boolean.rb', line 13

def cast(value)
  boolean = TRUE_VALUES.include?(value) ? true : nil
  return ValueResult.new(value: boolean, original_value: value) unless boolean.nil?

  boolean = FALSE_VALUES.include?(value) ? false : nil
  return ValueResult.new(value: boolean, original_value: value) unless boolean.nil?

  ValueResult.new(original_value: value, error_messages: ["`#{value.inspect}` can't be casted to Boolean"])
end