Method: Rsmart::ETL.parse_integer

Defined in:
lib/rsmart_toolbox/etl.rb

.parse_integer(str, opt = {}) ⇒ Integer?

Note:

Note the behavioral difference versus #to_i.

Parse an Integer from a String.

Examples:

Unlike #to_i, nil or empty inputs will return nil by default

nil == parse_integer(nil) && nil == parse_integer('') && 0 != parse_integer(nil)

Parameters:

  • str (String)

    the String to be parsed.

  • opt (Hash) (defaults to: {})

    options Hash will be passed through to #parse_string.

Returns:

  • (Integer, nil)

    the parsed Integer. nil or empty inputs will return nil by default.

See Also:



223
224
225
226
227
228
229
230
# File 'lib/rsmart_toolbox/etl.rb', line 223

def self.parse_integer(str, opt={})
  s = parse_string str, opt
  if s.empty?
    return nil;
  else
    return s.to_i
  end
end