Created
October 17, 2021 19:44
-
-
Save dnovais/a48f2bfda92f0ff05b244277f361be4f to your computer and use it in GitHub Desktop.
consonant and vowel count
This file contains hidden or 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
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