Class: CSVConverter::Converters::IntegerConverter

Inherits:
BaseConverter
  • Object
show all
Defined in:
lib/csv_converter/converters/integer_converter.rb

Overview

Converts a string into an integer

Instance Attribute Summary

Attributes inherited from BaseConverter

#options, #raw_data

Instance Method Summary collapse

Methods inherited from BaseConverter

#data, #empty_value?, #initialize

Constructor Details

This class inherits a constructor from CSVConverter::Converters::BaseConverter

Instance Method Details

#callInteger

Converts data into an Integer.

Returns:

  • (Integer)

    if an error occurs during conversion nil is returned.



9
10
11
12
13
# File 'lib/csv_converter/converters/integer_converter.rb', line 9

def call
  call!
rescue CSVConverter::Error
  nullable_object
end

#call!Integer

Converts data into an Integer.

Returns:

  • (Integer)

    if an error occurs during conversion an error is raised.



17
18
19
20
21
# File 'lib/csv_converter/converters/integer_converter.rb', line 17

def call!
  Integer(data)
rescue StandardError => e
  raise CSVConverter::Error.new(e.message, options)
end