Class: ContentLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/asker/loader/content_loader.rb

Instance Method Summary collapse

Instance Method Details

#call(filepath, content) ⇒ Object

Load XML content into Asker data objects

Parameters:

  • filepath (String)

    File path

  • content (String)

    XML plane text content



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/asker/loader/content_loader.rb', line 14

def call(filepath, content)
  begin
    xmlcontent = REXML::Document.new(content)
  rescue REXML::ParseException
    raise_error_with(filepath, content)
  end
  codes = []
  concepts = []
  problems = []
  lang = read_lang_attribute(xmlcontent)
  context = read_context_attribute(xmlcontent)

  xmlcontent.root.elements.each do |xmldata|
    case xmldata.name
    when "code"
      codes << read_code(xmldata, filepath)
    when "concept"
      concepts << read_concept(xmldata, filepath, lang, context)
    when "problem"
      problems << read_problem(xmldata, filepath, lang, context)
    else
      Logger.warn "ContentLoader: Unknown tag (#{xmldata.name}) Use concept, code or problem."
    end
  end

  {concepts: concepts, codes: codes, problems: problems}
end