class CurpGenerator::Element

Attributes

consonant_index[RW]
name[RW]
vowel_index[RW]

Public Class Methods

new(name) click to toggle source
# File lib/element.rb, line 9
def initialize(name)
  @name = name
  @consonant_index = 0
  @vowel_index = 0
end

Public Instance Methods

first_character() click to toggle source
# File lib/element.rb, line 15
def first_character
  return 'X' if blank_string?(name)

  character = name[0].upcase
  update_next_index_attribute(character)
  character == 'Ñ' ? 'X' : character
end
next_consonant() click to toggle source
# File lib/element.rb, line 23
def next_consonant
  return 'X' if blank_string?(name)

  consonants = CurpGenerator::StringFormat.new(name).remove_vowels.upcase
  consonants.size < 2 ? consonants[0] : consonants[consonant_index]
end
next_vowel() click to toggle source
# File lib/element.rb, line 30
def next_vowel
  return 'X' if blank_string?(name)

  consonants = CurpGenerator::StringFormat.new(name).remove_consonants.upcase
  consonants.size < 2 ? 'X' : consonants[vowel_index]
end

Private Instance Methods

update_next_index_attribute(character) click to toggle source
# File lib/element.rb, line 39
def update_next_index_attribute(character)
  new_consonant_value = CurpGenerator::StringFormat.new(character).consonant? ? 1 : 0
  new_vowel_value = CurpGenerator::StringFormat.new(character).vowel? ? 1 : 0
  self.consonant_index = new_consonant_value
  self.vowel_index = new_vowel_value
end