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 6
def initialize(float)
  @float = float
end

Public Instance Methods

fixed() click to toggle source
# File lib/thinking_sphinx/float_formatter.rb, line 10
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 32
def decimal_places
  exponent_factor + exponent_decimal_places
end
exponent_decimal_places() click to toggle source
# File lib/thinking_sphinx/float_formatter.rb, line 20
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 24
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 28
def exponent_present?
  float.to_s['e']
end