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
139 140 141 142 143 144 145 |
# File 'lib/data_cleansing/cleaners.rb', line 139 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 |