15
16
17
18
19
20
21
22
23
24
25
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
|
# File 'lib/wurfl_device/xml_loader.rb', line 15
def self.load_xml_file(wurfl_file, &blk)
begin
file_contents = File.open(wurfl_file).read.force_encoding('UTF-8')
rescue => e
raise XMLFileError, e.message
end
file_contents.gsub!(/\&\#x.+\;/, '')
doc = Ox.parse(file_contents)
doc.nodes.map do |elem1|
next unless elem1.value =~ /wurfl/i
elem1.nodes.map do |elem2|
version_info = Hash.new
if elem2.value == 'version'
elem2.nodes.map do |e|
if e.value == 'ver'
version_info[:version] = e.nodes[0].to_s
end
end
yield version_info if block_given?
end
if elem2.value == 'devices'
elem2.nodes.map do |device|
next unless device.value =~ /device/i
capabilities = Hash.new
capabilities['id'] = (device.attributes[:id] || '')
capabilities['user_agent'] = (device.attributes[:user_agent] || '')
capabilities['fall_back'] = (device.attributes[:fall_back] || '')
device.nodes.map do |group|
next unless group.value =~ /group/i
group.nodes.map do |capability|
capabilities[group.attributes[:id]] ||= Hash.new
next unless capability.value =~ /capability/i
capabilities[group.attributes[:id]][capability.attributes[:name]] = to_actual_value(capability.attributes[:value])
end
end
yield capabilities if block_given?
end
end
end
end
end
|