class CurpGenerator::StringFormat
Attributes
str[RW]
Public Class Methods
new(str)
click to toggle source
# File lib/string_format.rb, line 7 def initialize(str) @str = remove_special_chars(normalize(str.strip)) end
Public Instance Methods
consonant?()
click to toggle source
# File lib/string_format.rb, line 23 def consonant? !vowel? end
first_vowel()
click to toggle source
# File lib/string_format.rb, line 27 def first_vowel str.downcase.match(/a|e|i|o|u/).to_s.upcase end
remove_consonants()
click to toggle source
# File lib/string_format.rb, line 15 def remove_consonants str.downcase.tr('^aeiou', '') end
remove_vowels()
click to toggle source
# File lib/string_format.rb, line 11 def remove_vowels str.downcase.tr('aeiou', '') end
vowel?()
click to toggle source
# File lib/string_format.rb, line 19 def vowel? %w(A E I O U).include?(str.upcase) end
Private Instance Methods
normalize(string)
click to toggle source
# File lib/string_format.rb, line 33 def normalize(string) string&.tr( "ÀàÁáÄäÈèÉéËëÌìÍíÏïÒòÓóÖöÙùÚúÜüÑñ", "AaAaAaEeEeEeIiIiIiOoOoOoUuUuUuNn" ) end
remove_special_chars(string)
click to toggle source
# File lib/string_format.rb, line 40 def remove_special_chars(string) string&.gsub(/[\.\'\d-]/, "") end