Module: HanselCore::Formatting

Included in:
Hansel
Defined in:
lib/hansel/formatting/formatting.rb

Instance Method Summary collapse

Instance Method Details

#csv_formatterObject



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_outputObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/hansel/formatting/formatting.rb', line 40

def formatted_output
  formatter = "#{options.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_formatterObject



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 = options, (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, @port, description, num_conns.to_s ].compact.join('-')
        }).format
  end
end

#output_filenameObject



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' }[options.format.to_sym]
  @server, @port = (res = results.first) && res.server, res.port
  fname = [@server, @port, (part unless part.empty?)].compact.join('-')
  [ File.join( [options.output_dir, fname] ), type ].join('.')
end

#yaml_formatterObject



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