Last active
January 30, 2019 00:11
-
-
Save johnt1000/c7a8325e9b4510901503d613317b772c to your computer and use it in GitHub Desktop.
Script para abreviar nomes, escrito em Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
max_char = 13 | |
arr_nome = "Jonatas Rodrigues Alves".split | |
len_nome = 0 | |
abr_nome = "" | |
arr_nome.each_with_index do |palavra , i| | |
if i == 0 | |
abr_nome.concat(palavra) | |
else | |
len_previsto = palavra.length + 1 + len_nome.to_i | |
if (len_previsto >= max_char) | |
abr_nome.concat(" ").concat(palavra.split(//)[0]).concat(".") | |
else | |
abr_nome.concat(" ").concat(palavra) | |
end | |
end | |
len_nome = abr_nome.length | |
end | |
puts abr_nome |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Saída: