26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/rets4r/client/parsers/metadata.rb', line 26
def parse(doc)
rets_resources = {}
doc.get_elements('/RETS/*').each do |elem|
next unless TAGS.include?(elem.name)
columns = elem.get_elements('COLUMNS')[0]
rows = elem.get_elements('DATA')
data = @parser.parse_data(columns, rows)
resource_id = elem.attributes['Resource']
case elem.name
when 'METADATA-RESOURCE'
data.each do |resource_info|
id = resource_info.delete('ResourceID')
rets_resources[id] = resource_info
end
when 'METADATA-CLASS'
data.each do |class_info|
class_name = class_info.delete('ClassName')
rets_resources[resource_id][:classes] ||= {}
rets_resources[resource_id][:classes][class_name] = class_info
end
when 'METADATA-TABLE'
class_name = elem.attributes['Class']
data.each do |table_info|
system_name = table_info.delete('SystemName')
rets_resources[resource_id][:classes][class_name][:tables] ||= {}
rets_resources[resource_id][:classes][class_name][:tables][system_name] = table_info
end
when 'METADATA-OBJECT'
data.each do |object_info|
object_type = object_info.delete('ObjectType')
rets_resources[resource_id][:objects] ||= {}
rets_resources[resource_id][:objects][object_type] = object_info
end
when 'METADATA-LOOKUP'
data.each do |lookup_info|
lookup_name = lookup_info.delete('LookupName')
rets_resources[resource_id][:lookups] ||= {}
rets_resources[resource_id][:lookups][lookup_name] = lookup_info
end
when 'METADATA-LOOKUP_TYPE'
lookup = elem.attributes['Lookup']
rets_resources[resource_id][:lookup_types] ||= {}
rets_resources[resource_id][:lookup_types][lookup] = {}
data.each do |lookup_type_info|
value = lookup_type_info.delete('Value')
rets_resources[resource_id][:lookup_types][lookup][value] = lookup_type_info
end
end
end
rets_resources
end
|