class Orchestrator
Public Class Methods
new(tempLatexDirectory)
click to toggle source
# File lib/rubyplots/orchestrator.rb, line 17 def initialize(tempLatexDirectory) validateLatexPackages @tempLatexDirectory = tempLatexDirectory @latexFile = File.join(@tempLatexDirectory, 'RubyPlotsLatexFile.tex') writeOpeningTo @latexFile end
Public Instance Methods
addLatexFor(dataFile)
click to toggle source
# File lib/rubyplots/orchestrator.rb, line 24 def addLatexFor(dataFile) ScatterPlot.new( dataFile, @latexFile ) end
generatePlots()
click to toggle source
# File lib/rubyplots/orchestrator.rb, line 28 def generatePlots writeClosingTo @latexFile compile @latexFile end
savePlotsAndCleanup(latexDir)
click to toggle source
# File lib/rubyplots/orchestrator.rb, line 33 def savePlotsAndCleanup(latexDir) parentDir = File.dirname(latexDir) plotsToKeep = Dir.glob(latexDir + File::SEPARATOR + "rubyplots-*.pdf") plotsToKeep.each do |plot| FileUtils.move(plot, parentDir, {:force => true}) end # Todo: Review options for this remove - this is unsecure right now. FileUtils.rm_rf @tempLatexDirectory end
Private Instance Methods
compile(pathToLatex)
click to toggle source
# File lib/rubyplots/orchestrator.rb, line 46 def compile(pathToLatex) latexDir = File.split(pathToLatex)[0] file = File.split(pathToLatex)[1] FileUtils.cd latexDir enableLatexSystemCallsFor file system "pdflatex #{file} > /dev/null" end
enableLatexSystemCallsFor(latex)
click to toggle source
A requirement of generating individual PDF’s Todo: Figure out why you get 2 errors here that don’t seem to effect compilation…
# File lib/rubyplots/orchestrator.rb, line 57 def enableLatexSystemCallsFor(latex) system "pdflatex -shell-escape #{File.basename(latex, ".tex")} > /dev/null" end
validateLatexPackages()
click to toggle source
Validates that latex, tikz, and pgfplots are installed
# File lib/rubyplots/orchestrator.rb, line 62 def validateLatexPackages if which("pdflatex").nil? || !(system "kpsewhich tikz > /dev/null") || !(system "kpsewhich pgfplots > /dev/null") raise "Missing required latex packages." end end
which(cmd)
click to toggle source
# File lib/rubyplots/orchestrator.rb, line 68 def which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each { |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable? exe } end return nil end
writeClosingTo(file)
click to toggle source
# File lib/rubyplots/orchestrator.rb, line 90 def writeClosingTo(file) File.open(file, "a") do |f| f << '\\end{document}' end end
writeOpeningTo(file)
click to toggle source
# File lib/rubyplots/orchestrator.rb, line 79 def writeOpeningTo(file) File.open(file, "a") do |f| f << '\\documentclass{article}' + "\n" f << '\\usepackage{pgfplots}' + "\n" f << '\\pgfplotsset{compat = newest}' + "\n" f << '\\usepgfplotslibrary{external}' + "\n" f << '\\tikzexternalize' + "{#{File.basename(file, ".tex")}}\n" f << '\\begin{document}' + "\n" end end