Module: HanselCore::Formatting
- Included in:
- Hansel
- Defined in:
- lib/hansel/formatting/formatting.rb
Instance Method Summary collapse
- #csv_formatter ⇒ Object
- #formatted_output ⇒ Object
- #octave_formatter ⇒ Object
- #output_filename ⇒ Object
- #yaml_formatter ⇒ Object
Instance Method Details
#csv_formatter ⇒ Object
12 13 14 15 16 |
# File 'lib/hansel/formatting/formatting.rb', line 12 def csv_formatter File.open(output_filename, "w+") do |file| file.puts CsvFormatter.format results end end |
#formatted_output ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/hansel/formatting/formatting.rb', line 40 def formatted_output formatter = "#{.format}_formatter".to_sym unless self.respond_to? formatter status "Using default octave_formatter" octave_formatter else status "Using #{formatter}" self.send formatter end end |
#octave_formatter ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/hansel/formatting/formatting.rb', line 18 def octave_formatter res = results opts, num_conns = , (res.first.num_conns rescue nil) file_name = output_filename{ "#{num_conns.to_s}" } template_name = (opts.template && opts.template + '.m.erb') || 'octave.m.erb' template = File.join( [ File.dirname(__FILE__), '../../..', opts.template_path, template_name ] ) description = @current_job && @current_job.description File.open(file_name, "w+") do |file| file.puts OctaveFormatter.new(res, { :output_file_name => file_name, :template => template, :description => @description, :png_file_name => [ @server.gsub('.', '_'), @port, description, num_conns.to_s ].compact.join('_') }).format end end |
#output_filename ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/hansel/formatting/formatting.rb', line 51 def output_filename part = [ @current_job && @current_job.description, ( yield if block_given? ) ].compact type = { :yaml => 'yml', :csv => 'csv', :octave => 'm' }[.format.to_sym] @server, @port, @num_conns = (res = results.first) && res.server, res.port, res.num_conns fname = [ @server.gsub('.', '_'), @port, (part unless part.empty?), @num_conns ].compact.join('_') [ File.join( [.output_dir, fname] ), type ].join('.') end |
#yaml_formatter ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/hansel/formatting/formatting.rb', line 3 def yaml_formatter File.open(output_filename, "w+") do |file| file.puts YamlFormatter.format results # file.puts YamlFormatter.format results.merge({ # :description => @current_job.description # }) end end |