require 'erb'

module Plugin

	class ResultsHelper
		
		def initialize(plugin,template)
			@plugin = plugin
			
			
			tf = File.open(template,"r")
			@template = tf.read() unless tf.nil?
			tf.close unless tf.nil?
		end
		
    def format(arg)
      if(arg.is_a? Float)
        
        if(arg.abs > 999.0 || arg.abs < 0.0001)
          sprintf("%0.4E",arg)
        else
          sprintf("%0.5f",arg)
        end
        
      else
        arg
      end
    end
		
		def to_s
			eng = ERB.new(@template)
			eng.result binding
		end
		
	end

end # module Plugin