dynarex 0.2.8 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dynarex.rb +9 -5
- metadata +1 -1
data/lib/dynarex.rb
CHANGED
@@ -44,8 +44,9 @@ class Dynarex
|
|
44
44
|
end
|
45
45
|
xml.records do
|
46
46
|
@records.each do |k, item|
|
47
|
-
xml.send(@item_name, id: item[:id],
|
48
|
-
item[:
|
47
|
+
xml.send(@item_name, id: item[:id], created: item[:created], \
|
48
|
+
last_modified: item[:last_modified]) do
|
49
|
+
item[:body].each{|name,value| xml.send name, value}
|
49
50
|
end
|
50
51
|
end
|
51
52
|
end
|
@@ -76,14 +77,17 @@ class Dynarex
|
|
76
77
|
|
77
78
|
def records_to_h(default_key)
|
78
79
|
ah = XPath.match(@doc.root, 'records/*').each_with_index.map do |row,i|
|
79
|
-
|
80
|
+
created = Time.now.to_s; id = Time.now.strftime("%Y%m%I%H%M%S") + i.to_s
|
81
|
+
last_modified = ''
|
80
82
|
id = row.attribute('id').value.to_s if row.attribute('id')
|
81
|
-
|
83
|
+
created = row.attribute('created').value.to_s if row.attribute('created')
|
84
|
+
last_modified = row.attribute('last_modified').value.to_s if row.attribute('last_modified')
|
82
85
|
body = XPath.match(row, '*').inject({}) do |r,node|
|
83
86
|
r[node.name.to_s.to_sym] = node.text.to_s
|
84
87
|
r
|
85
88
|
end
|
86
|
-
[body[default_key.to_sym],{id: id,
|
89
|
+
[body[default_key.to_sym],{id: id, created: created, last_modified: \
|
90
|
+
last_modified, body: body}]
|
87
91
|
end
|
88
92
|
Hash[*ah.flatten]
|
89
93
|
end
|