Class: CSVConverter::Converters::BooleanConverter
- Inherits:
-
BaseConverter
- Object
- BaseConverter
- CSVConverter::Converters::BooleanConverter
- Defined in:
- lib/csv_converter/converters/boolean_converter.rb
Overview
Converts a string into a boolean
Instance Attribute Summary
Attributes inherited from BaseConverter
Instance Method Summary collapse
-
#call ⇒ Boolean
Converts data into a Boolean by checking if data is contained in the list of truthy_values provided in the mappings.
-
#call! ⇒ Boolean
Converts data into a Boolean by checking if data is contained in the list of truthy_values provided in the mappings.
-
#initialize(raw_data, options = { truthy_values: %w[true false] }) ⇒ BooleanConverter
constructor
A new instance of BooleanConverter.
Methods inherited from BaseConverter
Constructor Details
#initialize(raw_data, options = { truthy_values: %w[true false] }) ⇒ BooleanConverter
A new instance of BooleanConverter.
12 13 14 15 16 |
# File 'lib/csv_converter/converters/boolean_converter.rb', line 12 def initialize(raw_data, = { truthy_values: %w[true false] }) super(raw_data, ) end |
Instance Method Details
#call ⇒ Boolean
Converts data into a Boolean by checking if data is contained in the list of truthy_values provided in the mappings.
21 22 23 24 25 |
# File 'lib/csv_converter/converters/boolean_converter.rb', line 21 def call call! rescue CSVConverter::Error nullable_object end |
#call! ⇒ Boolean
Converts data into a Boolean by checking if data is contained in the list of truthy_values provided in the mappings.
30 31 32 33 34 |
# File 'lib/csv_converter/converters/boolean_converter.rb', line 30 def call! [:truthy_values].include?(data) rescue StandardError => e raise CSVConverter::Error.new(e., ) end |