Class: ExportManager

Inherits:
Object
  • Object
show all
Defined in:
lib/teuton/case_manager/export_manager.rb

Overview

Execute “export” order: Export every case report

Instance Method Summary collapse

Instance Method Details

#call(main_report, cases, args, default_format) ⇒ Object

Run export function

Parameters:

  • main_report (Report)
  • cases (Array)
  • input (Hash)

    Selected export options



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/teuton/case_manager/export_manager.rb', line 16

def call(main_report, cases, args, default_format)
  if args.class != Hash
    puts Rainbow("[ERROR] ExportManager:").red
    puts Rainbow("  Export argument error!").red
    puts Rainbow("  Revise: export #{args}").red
    puts Rainbow("  Use   : export format: 'txt'").red
    puts ""
    exit 1
  end

  # Step 1: Validate options
  options = strings2symbols(args)
  options[:format] = default_format if options[:format].nil?

  unless Formatter.available_formats.include? options[:format]
    puts Rainbow("[WARN] ExportManager:").yellow.bright
    puts Rainbow("       Unkown format <#{options[:format]}>. Fix line <export format: FORMAT>.").yellow.bright
    puts Rainbow("       Available formats: #{Formatter.available_formats.join(", ")}.").yellow.bright
    puts Rainbow("[INFO] Using default format <txt>.").yellow.bright
    options[:format] = :txt
  end

  # Step 2: Export case reports
  threads = []
  cases.each { |c| threads << Thread.new { c.export(options) } }
  threads.each(&:join)

  # Step 3: Export resume report
  main_report.export_resume(options)

  # Step 4: Preserve files if required
  preserve_files if options[:preserve] == true
end