Module: HanselCore::Formatting

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

Instance Method Summary collapse

Instance Method Details

#csv_formatterObject



9
10
11
12
13
# File 'lib/hansel/formatting/formatting.rb', line 9

def csv_formatter
  File.open(output_filename, "w+") do |file|
    file.puts CsvFormatter.format results
  end
end

#formatted_outputObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/hansel/formatting/formatting.rb', line 37

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



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hansel/formatting/formatting.rb', line 15

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



48
49
50
51
52
53
54
# File 'lib/hansel/formatting/formatting.rb', line 48

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
# File 'lib/hansel/formatting/formatting.rb', line 3

def yaml_formatter
  File.open(output_filename, "w+") do |file|
    file.puts YamlFormatter.format results
  end
end