Skip to content

Instantly share code, notes, and snippets.

@johnt1000
Last active January 30, 2019 00:11
Show Gist options
  • Save johnt1000/c7a8325e9b4510901503d613317b772c to your computer and use it in GitHub Desktop.
Save johnt1000/c7a8325e9b4510901503d613317b772c to your computer and use it in GitHub Desktop.
Script para abreviar nomes, escrito em Ruby
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
@johnt1000
Copy link
Author

Saída:

captura de tela 2019-01-29 as 20 40 32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment