Module: ContentLoader
- Defined in:
- lib/asker/loader/content_loader.rb
Overview
Define methods that load data from XML contents
Class Method Summary collapse
-
.load(filepath, content) ⇒ Object
Load XML content into Asker data objects rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize.
Class Method Details
.load(filepath, content) ⇒ Object
Load XML content into Asker data objects rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/asker/loader/content_loader.rb', line 18 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 Logger.verboseln Rainbow("[ERROR] Unkown tag <#{xmldata.name}>").red end end { concepts: concepts, codes: codes } end |