Module: Cleaners::StringToInteger
- Defined in:
- lib/data_cleansing/cleaners.rb
Overview
Returns [Integer] after removing all non-digit characters, except ‘.’ Returns nil if no digits are present in the string.
Constant Summary collapse
- NUMERIC =
Regexp.compile(/[^0-9\.]/)
Class Method Summary collapse
Class Method Details
.call(string) ⇒ Object
135 136 137 138 139 140 141 |
# File 'lib/data_cleansing/cleaners.rb', line 135 def self.call(string) return string unless string.is_a?(String) # Remove Non-Digit Chars, except for '.' string.gsub!(NUMERIC, '') string.length > 0 ? string.to_i : nil end |