Class: MedievalLatina::LexiconBuilder

Inherits:
Object
  • Object
show all
Includes:
REXML
Defined in:
lib/medieval_latina/lexicon_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(words, lang: "en-US") ⇒ LexiconBuilder

Returns a new instance of LexiconBuilder.



8
9
10
11
12
# File 'lib/medieval_latina/lexicon_builder.rb', line 8

def initialize(words, lang: "en-US")
  @document = Document.new
  @words = words
  @lang = lang
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/medieval_latina/lexicon_builder.rb', line 14

def call
  document.add_element "lexicon", SPECIFICATION.merge("xml:lang" => lang)

  words.each do |word, pronunciation|
    lexeme = Element.new("lexeme")
    grapheme = Element.new("grapheme")
    phoneme = Element.new("phoneme")

    grapheme.text = CGI.unescapeHTML(word)
    phoneme.text = pronunciation

    lexeme.add_element(grapheme)
    lexeme.add_element(phoneme)

    document.root.add_element(lexeme)
  end

  document
end