Skip to content

Instantly share code, notes, and snippets.

@dnovais
Created October 17, 2021 19:44
Show Gist options
  • Save dnovais/a48f2bfda92f0ff05b244277f361be4f to your computer and use it in GitHub Desktop.
Save dnovais/a48f2bfda92f0ff05b244277f361be4f to your computer and use it in GitHub Desktop.
consonant and vowel count
require "i18n"
I18n.available_locales = [:en]
def vowels_and_consonants(string)
string
.then{|string| transliterate(string)}
.then{|string| letters(string)}
.then{|string| vowels_and_consonants_count(string)}
end
def vowels_and_consonants_count(string)
string_total = string.size
vowels_count = string.downcase.scan(/[aeiou]/).size
consonants_count = string_total - vowels_count
"Vowels: #{vowels_count} and Consonants: #{consonants_count}"
end
def letters(string)
string.gsub(/[\W]/, '')
end
def transliterate(string)
I18n.transliterate(string)
end
string = "O período é uma unidade sintática."
vowels_and_consonants(string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment