module BlackStack::Number::Encoding


Encoding


Public Class Methods

encode_minutes(n) click to toggle source

Convierte una cantidad de minutos a una leyenda legible por el usuario. Ejemplo: “2 days, 5 hours” Ejemplo: “4 hours, 30 minutes” Ejemplo: “3 days, 4 hour”

# File lib/functions.rb, line 98
def self.encode_minutes(n)
  # TODO: validar que n sea un entero mayor a 0
  if (n<0)
    return "?"
  end
  if (n<60)
    return "#{n} minutes"
  elsif (n<24*60)
    return "#{(n/60).to_i} hours, #{n-60*(n/60).to_i} minutes"
  else
    return "#{(n/(24*60)).to_i} days, #{((n-24*60*(n/(24*60)).to_i)/60).to_i} hours"
  end
end
format_with_separator(number) click to toggle source

Converts number to a string with a format like xx,xxx,xxx.xxxx number: it may be int or float

# File lib/functions.rb, line 89
def self.format_with_separator(number)
  whole_part, decimal_part = number.to_s.split('.')
  [whole_part.gsub(/(\d)(?=\d{3}+$)/, '\1,'), decimal_part].compact.join('.')
end