Module: ContentLoader

Defined in:
lib/asker/loader/content_loader.rb

Overview

Define methods that load data from XML contents

Class Method Summary collapse

Class Method Details

.load(filepath, content) ⇒ Object

Load XML content into Asker data objects

Parameters:

  • filepath (String)

    File path

  • content (String)

    XML plane text content



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

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

  xmlcontent.root.elements.each do |xmldata|
    case xmldata.name
    when "concept"
      concepts << read_concept(xmldata, filepath, lang, context)
    when "code"
      codes << read_code(xmldata, filepath)
    else
      puts Rainbow("[ERROR] Unkown tag: #{xmldata.name}").red
      puts Rainbow("[INFO ] Only 'concept' and 'code' are available at this level").red
    end
  end

  { concepts: concepts, codes: codes }
end