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
91 92 93 |
# File 'lib/ultrasphinx/core_extensions.rb', line 91 def _interpolate(value) self.sub('?', value) end |
#_to_numeric ⇒ Object
XXX Not used enough to justify such a strange abstraction
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ultrasphinx/core_extensions.rb', line 77 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 |