Class: Dmcli::XmlExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/dmcli/xml_exporter.rb

Overview

XmlExporter Utility class for exporting data to a XML file. Used to compile a large number of individual XML files into one large XML file.

Instance Method Summary collapse

Instance Method Details

#builder(target, output) ⇒ Object



10
11
12
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
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dmcli/xml_exporter.rb', line 10

def builder(
  target,
  output
)

  loader = DndDataLoader.new
  spells = loader.load_spells(target, "BECMI", "any", "any")

  xml_contents = Nokogiri::XML::Builder.new do |xml|
    xml.spellList("xmlns" => "dungeon", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation" => "dungeon spells.xsd") do
      spells.each do |s|
        xml.spell do
          xml.name s.name
          xml.editions do
            xml.editionBECMI do
              xml.is_reversible s.is_reversible
              xml.class_ s.spell_class
              xml.level s.spell_level
              xml.range s.range
              xml.duration s.range
              xml.effect s.effect
              xml.description s.description_text
              xml.sources do
                xml.source "Dungeons and Dragons Rules Cyclopedia, p42"
              end
            end
          end
        end
      end
    end
  end

  puts "Exporting to #{output}"
  File.open(output, "w") do |f|
    f.write(xml_contents.to_xml)
  end

  filesize = File.size(output) / 1024
  puts "#{filesize} kb written"
end