class ThinkingSphinx::FloatFormatter

Constants

PATTERN

Attributes

float[R]

Public Class Methods

new(float) click to toggle source
# File lib/thinking_sphinx/float_formatter.rb, line 4
def initialize(float)
  @float = float
end

Public Instance Methods

fixed() click to toggle source
# File lib/thinking_sphinx/float_formatter.rb, line 8
def fixed
  return float.to_s unless exponent_present?

  ("%0.#{decimal_places}f" % float).gsub(/0+$/, '')
end

Private Instance Methods

decimal_places() click to toggle source
# File lib/thinking_sphinx/float_formatter.rb, line 30
def decimal_places
  exponent_factor + exponent_decimal_places
end
exponent_decimal_places() click to toggle source
# File lib/thinking_sphinx/float_formatter.rb, line 18
def exponent_decimal_places
  float.to_s[PATTERN, 1].length
end
exponent_factor() click to toggle source
# File lib/thinking_sphinx/float_formatter.rb, line 22
def exponent_factor
  float.to_s[PATTERN, 2].to_i
end
exponent_present?() click to toggle source
# File lib/thinking_sphinx/float_formatter.rb, line 26
def exponent_present?
  float.to_s['e']
end