module Telemetry::NumberHelper

Public Class Methods

convert_to_number(string) click to toggle source
# File lib/telemetry/number_helper.rb, line 18
def convert_to_number(string)
  if integer?(string)
    string.to_i
  elsif float?(string)
    string.to_f
  else
    string
  end
end
float?(string) click to toggle source
# File lib/telemetry/number_helper.rb, line 8
def float?(string)
  string == string.to_f.to_s
end
integer?(string) click to toggle source
# File lib/telemetry/number_helper.rb, line 13
def integer?(string)
  string == string.to_i.to_s
end
number?(str) click to toggle source
# File lib/telemetry/number_helper.rb, line 3
def number?(str)
  [str.to_f.to_s, str.to_i.to_s].include?(str)
end

Private Instance Methods

convert_to_number(string) click to toggle source
# File lib/telemetry/number_helper.rb, line 18
def convert_to_number(string)
  if integer?(string)
    string.to_i
  elsif float?(string)
    string.to_f
  else
    string
  end
end
float?(string) click to toggle source
# File lib/telemetry/number_helper.rb, line 8
def float?(string)
  string == string.to_f.to_s
end
integer?(string) click to toggle source
# File lib/telemetry/number_helper.rb, line 13
def integer?(string)
  string == string.to_i.to_s
end
number?(str) click to toggle source
# File lib/telemetry/number_helper.rb, line 3
def number?(str)
  [str.to_f.to_s, str.to_i.to_s].include?(str)
end