Class: DoctorNinja::Parsers::Drawing
- Inherits:
-
Base
- Object
- Base
- DoctorNinja::Parsers::Drawing
show all
- Includes:
- Magick
- Defined in:
- lib/doctor_ninja/parsers/drawing.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #parse_children
Class Method Details
.applicable_to?(node) ⇒ Boolean
7
8
9
|
# File 'lib/doctor_ninja/parsers/drawing.rb', line 7
def self.applicable_to?(node)
node.name == "drawing"
end
|
Instance Method Details
#extent ⇒ Object
25
26
27
28
29
30
|
# File 'lib/doctor_ninja/parsers/drawing.rb', line 25
def extent
@extent ||= {
x: extent_node.attribute("cx").value.to_i,
y: extent_node.attribute("cy").value.to_i
}
end
|
#extent_node ⇒ Object
32
33
34
|
# File 'lib/doctor_ninja/parsers/drawing.rb', line 32
def extent_node
@node.xpath(".//wp:extent")
end
|
#parse ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/doctor_ninja/parsers/drawing.rb', line 11
def parse
width = extent[:x]/DoctorNinja::EMU_PER_PIXEL
height = extent[:y]/DoctorNinja::EMU_PER_PIXEL
rvg = RVG.new(width,height).viewbox(0,0,width,height) do |canvas|
parse_children(canvas)
end
format = "png"
base64 = Base64.encode64 rvg.draw.to_blob { self.format = format }
"<img src=\"data:image/#{format};base64,#{base64}\"/>"
end
|