Class: DataMaps::Converter::Numeric
- Inherits:
-
Base
- Object
- Executable
- Base
- DataMaps::Converter::Numeric
- Defined in:
- lib/data_maps/converter/numeric.rb
Overview
Converts numeric values
Instance Attribute Summary
Attributes inherited from Executable
Instance Method Summary collapse
-
#execute(data) ⇒ Object
The execute method to convert the given data.
Methods inherited from Executable
#initialize, valid_collection?
Constructor Details
This class inherits a constructor from DataMaps::Executable
Instance Method Details
#execute(data) ⇒ Object
The execute method to convert the given data
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/data_maps/converter/numeric.rb', line 10 def execute(data) raise DataMaps::Errors::InvalidDataError.new("The given data is not a numeric: #{data}") unless is_numeric?(data) case option when 'Integer' then data.to_i when 'Float' then data.to_f when Integer then data.to_f.round(option) else data end end |