Skip to content

Instantly share code, notes, and snippets.

@BrandonMathis
Created January 31, 2011 21:56
Show Gist options
  • Save BrandonMathis/804908 to your computer and use it in GitHub Desktop.
Save BrandonMathis/804908 to your computer and use it in GitHub Desktop.
JRuby Nokogiri generate CCOM type raketask
<?xml version="1.0" encoding="UTF-8"?>
<root>
<Entity xsi:type="EntityType">
<GUID>c014e3c1-0fb2-012e-8f94-549a20e02a6a</GUID>
<Tag>Adapter Plate</Tag>
<Status>1</Status>
</Entity>
</root>
# --
# Will generate a series of MLoc EntityTypes for each define Type in the given FILE (one type per line)
# --
desc "parse a FILE and generate a series of CCOM Types (of type TYPE) for each line and outputs into TARGET"
task :gen_type => :environment do
types = File.open("./samples/meas_loc_sorted").map { |line| line.chomp! }
builder = Nokogiri::XML::Builder.new do |xml|
xml.root do
types.each do |type|
xml.Entity "xsi:type" => ENV['TYPE'] do
xml.GUID UUID.generate
xml.Tag type
xml.Status "1"
end
end
end
end
File.open(File.join("samples", ENV['TARGET']), 'w') {|f| f.write(builder.to_xml(:indent => 2, :encoding => 'UTF-8'))}
end
<?xml version="1.0" encoding="UTF-8"?>
<root>
<Entity xsi:type="EntityType">
<GUID>c014e3c1-0fb2-012e-8f94-549a20e02a6a</GUID><Tag>Adapter Plate</Tag><Status>1</Status>
</Entity>
</root>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment