Method: DataTools.scour
- Defined in:
- lib/data_tools.rb
.scour(s, opts = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/data_tools.rb', line 11 def DataTools.scour(s, opts = {}) case s when nil nil when String s2 = s.strip.gsub(/\s+/, ' ') if s2 =~ /^".*"$/ s2 = s2.gsub(/^"/, '').gsub(/"$/, '') end if s2 =~ /^[\d]+(\.[\d]+){0,1}$/ # looks numeric s2 = s2.to_i.to_s end (s2.empty? || (opts[:junkwords]||[]).include?(s2)) ? nil : s2 when Numeric s.to_s else s.to_s end end |