class DataMaps::Converter::Numeric

Converts numeric values

@since 0.0.1

Public Instance Methods

execute(data) click to toggle source

The execute method to convert the given data

@param [mixed] data

# 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

Private Instance Methods

is_numeric?(data) click to toggle source
# File lib/data_maps/converter/numeric.rb, line 23
def is_numeric?(data)
  true if Float(data) rescue false
end