dynarex 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/dynarex.rb +23 -1
- metadata +1 -1
data/lib/dynarex.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'rexml/document'
|
4
4
|
require 'open-uri'
|
5
|
+
require 'builder'
|
5
6
|
|
6
7
|
class Dynarex
|
7
8
|
include REXML
|
@@ -19,7 +20,26 @@ class Dynarex
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def save(filepath)
|
22
|
-
|
23
|
+
|
24
|
+
xml = Builder::XmlMarkup.new( :target => buffer='', :indent => 2 )
|
25
|
+
xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
|
26
|
+
|
27
|
+
xml.send @root_name do
|
28
|
+
xml.summary do
|
29
|
+
dynarex.summary.each{|key,value| xml.send key, value}
|
30
|
+
end
|
31
|
+
xml.records do
|
32
|
+
dynarex.records.each do |item|
|
33
|
+
xml.send @item_name do
|
34
|
+
item.each do |key, value|
|
35
|
+
xml.send key, value
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
File.open(filepath,'w'){|f| f.write buffer}
|
23
43
|
end
|
24
44
|
|
25
45
|
private
|
@@ -35,6 +55,8 @@ class Dynarex
|
|
35
55
|
@doc = Document.new buffer
|
36
56
|
@summary = summary_to_h
|
37
57
|
@records = records_to_h
|
58
|
+
@root_name = doc.root.name
|
59
|
+
@item_name = XPath.first(@doc.root, 'records/*[1]').name
|
38
60
|
end
|
39
61
|
|
40
62
|
def display()
|