Module: Cleaners::StringToFloat
- 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
154 155 156 157 158 159 160 |
# File 'lib/data_cleansing/cleaners.rb', line 154 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_f : nil end |