10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/svgcode.rb', line 10
def self.parse(xml_str, opts = {})
doc = Nokogiri.parse(xml_str)
doc.remove_namespaces!
view_box = doc.xpath('/svg').first.attributes['viewBox'].value
opts[:max_y] = view_box.split(/\s+/).last.to_f
converter = Converter.new(opts)
doc.xpath('//path').each do |path|
if opts[:comments]
ids = path.xpath('ancestor::g[@id]').collect do |t|
t.attributes['id'].value
end
converter.(ids.join(' '))
end
converter.transforms = path.xpath('ancestor::g[@transform]').collect do |t|
Transform.new(t.attributes['transform'].value)
end
converter << path.attributes['d'].value
end
converter.finish
converter.to_s
end
|