Class: Nyaplot::Plot
- Inherits:
-
Object
- Object
- Nyaplot::Plot
- Defined in:
- lib/nyaplot/export_svg.rb
Constant Summary collapse
- SVG_HEADER =
'<svg xmlns="http://www.w3.org/2000/svg">'- SVG_CLOSE =
'</svg>'- TEMP_NAME =
'temp.html'
Instance Method Summary collapse
-
#export_contents(name = SecureRandom.uuid.to_s + ".svg") ⇒ Object
Export context of plot as SVG.
-
#export_svg(name = SecureRandom.uuid.to_s + ".svg") ⇒ Object
Export plot as SVG.
-
#get_nodes ⇒ String
Get html nodes created by JavaScript with browsers.
Instance Method Details
#export_contents(name = SecureRandom.uuid.to_s + ".svg") ⇒ Object
Export context of plot as SVG
35 36 37 38 39 40 41 |
# File 'lib/nyaplot/export_svg.rb', line 35 def export_contents(name=SecureRandom.uuid.to_s + ".svg") html = get_nodes contents = Nokogiri::HTML.parse(html).at('.context_child').to_s str = SVG_HEADER + contents + SVG_CLOSE path = File.("./" + name, Dir.pwd) File.write(path, str) end |
#export_svg(name = SecureRandom.uuid.to_s + ".svg") ⇒ Object
Export plot as SVG
26 27 28 29 30 31 |
# File 'lib/nyaplot/export_svg.rb', line 26 def export_svg(name=SecureRandom.uuid.to_s + ".svg") html = get_nodes str = Nokogiri::HTML.parse(html).xpath('//svg').to_s path = File.("./" + name, Dir.pwd) File.write(path, str) end |
#get_nodes ⇒ String
Get html nodes created by JavaScript with browsers
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/nyaplot/export_svg.rb', line 13 def get_nodes require 'watir' self.export_html(TEMP_NAME) path = File.("./" + TEMP_NAME, Dir.pwd) browser = Watir::Browser.start("file://" + path) html = browser.html browser.close FileUtils.rm_r(path) return html end |