7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/rbraspag/utils.rb', line 7
def self.convert_to_map(document, map = {})
document = Nokogiri::XML(document)
map.each do |key, value|
if value.is_a?(String) || value.nil?
value = key if value.nil?
new_value = document.search(value).first
if new_value.nil?
map[key] = nil
else
new_value = new_value.content.to_s
map[key] = new_value unless new_value == ""
map[key] = nil if new_value == ""
end
elsif value.is_a?(Proc)
map[key] = value.call(document)
end
end
map
end
|