Class: String
Overview
Filter type coercion methods
Instance Method Summary collapse
- #_interpolate(value) ⇒ Object
-
#_to_numeric ⇒ Object
XXX Not used enough to justify such a strange abstraction.
Instance Method Details
#_interpolate(value) ⇒ Object
80 81 82 |
# File 'lib/ultrasphinx/core_extensions.rb', line 80 def _interpolate(value) self.sub('?', value) end |
#_to_numeric ⇒ Object
XXX Not used enough to justify such a strange abstraction
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ultrasphinx/core_extensions.rb', line 66 def _to_numeric zeroless = self.squeeze(" ").strip.sub(/^0+(\d)/, '\1') zeroless.sub!(/(\...*?)0+$/, '\1') if zeroless.to_i.to_s == zeroless zeroless.to_i elsif zeroless.to_f.to_s == zeroless zeroless.to_f elsif date = Chronic.parse(self.gsub(/(\d)([^\d\:\s])/, '\1 \2')) # Improve Chronic's flexibility a little date.to_i else raise Ultrasphinx::UsageError, "#{self.inspect} could not be coerced into a numeric value" end end |