Class: HowIs::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/how_is/report.rb

Overview

Report control class with class methods to make reports for an analysis or to save reports in files, or otherwise interact with the files.

Class Method Summary collapse

Class Method Details

.export(analysis, format = HowIs::DEFAULT_FORMAT) ⇒ Object

Export a report to a String.



31
32
33
34
35
# File 'lib/how_is/report.rb', line 31

def self.export(analysis, format = HowIs::DEFAULT_FORMAT)
  report = get_report_class(format).new(analysis)

  report.export
end

.export_file(analysis, file) ⇒ Object

Export a report to a file.



22
23
24
25
26
27
# File 'lib/how_is/report.rb', line 22

def self.export_file(analysis, file)
  format = file.split(".").last
  report = get_report_class(format).new(analysis)

  report.export_file(file)
end

.infer_format(file) ⇒ String

Returns the report format for given filename.

Parameters:

  • file (String)

    Filename of a report

Returns:

  • (String)

    Report format inferred from file name



54
55
56
# File 'lib/how_is/report.rb', line 54

def self.infer_format(file)
  Pathname(file).extname.delete(".")
end

.save_report(file, report) ⇒ Object

Saves given Report in given file.

Parameters:

  • file (String, Pathname)

    Name of file to write to

  • report (Report)

    Report to store



42
43
44
45
46
# File 'lib/how_is/report.rb', line 42

def self.save_report(file, report)
  File.open(file, "w") do |f|
    f.write report
  end
end

.to_format_based_on(file, report) ⇒ String

Exports given report to the format suitable for given file.

Parameters:

  • file (String, Pathname)
  • report (Report)

Returns:

  • (String)

    The rendered report



65
66
67
68
69
# File 'lib/how_is/report.rb', line 65

def self.to_format_based_on(file, report)
  report_format = infer_format(file)

  report.public_send("to_#{report_format}")
end