class MedievalLatina

Constants

CONSONENTS
CONSONENT_TEAMS
DICTIONARY
Result
SOFT_C
SOFT_G
SOFT_T
VERSION
VOWELS
VOWEL_TEAMS

Attributes

index[RW]
word[R]

Public Class Methods

[](text) click to toggle source
# File lib/medieval_latina.rb, line 5
def self.[](text)
  text.split(" ").map { |word|
    DICTIONARY[word.downcase] || new(word).call
  }.join(" ")
end
new(word) click to toggle source
# File lib/medieval_latina.rb, line 11
def initialize(word)
  @index = 0
  @word = word.downcase
end

Public Instance Methods

call() click to toggle source
# File lib/medieval_latina.rb, line 16
def call
  array = []

  until index >= word.length
    substring = Substring.new(word, index)
    result = vowel(substring) || consonant(substring) || Result.new(substring.character, 1)
    array.push(result.substring)
    self.index = index + result.increment_by
  end

  array.join("")
end

Private Instance Methods

consonant(substring) click to toggle source
# File lib/medieval_latina.rb, line 50
def consonant(substring)
  consonant_team = CONSONENT_TEAMS[substring.to_team]
  consonant = if CONSONENTS.key?(substring.character.intern)
    CONSONENTS[substring.character.intern].call(substring.rest)
  end

  if consonant_team
    Result.new(consonant_team, 2)
  elsif consonant
    Result.new(consonant, 1)
  end
end
vowel(substring) click to toggle source
# File lib/medieval_latina.rb, line 63
def vowel(substring)
  vowel_team = VOWEL_TEAMS[substring.to_team]
  vowel = VOWELS[substring.character.intern]

  if vowel_team
    Result.new(vowel_team, 2)
  elsif vowel
    Result.new(vowel, 1)
  end
end