Module: HowIs

Defined in:
lib/how_is.rb,
lib/how_is/report.rb,
lib/how_is/sources.rb,
lib/how_is/version.rb,
lib/how_is/frontmatter.rb,
lib/how_is/sources/github.rb,
lib/how_is/sources/github_helpers.rb

Defined Under Namespace

Modules: CLI, Frontmatter, Sources Classes: Report

Constant Summary collapse

DEFAULT_REPORT_FILE =
"report.html"
VERSION =
"20.0.0"

Class Method Summary collapse

Class Method Details

.can_export_to?(file) ⇒ Boolean

Returns whether or not the specified file can be exported to.

Parameters:

  • file (String)

    A filename.

Returns:

  • (Boolean)

    true if HowIs can export to the file, false if it can’t.



92
93
94
95
# File 'lib/how_is.rb', line 92

def self.can_export_to?(file)
  # TODO: Check if the file is writable?
  supported_formats.include?(file.split(".").last)
end

.from_config(config, date) ⇒ Object

Generates a series of report files based on a config Hash.

Parameters:

  • config (Hash)

    A Hash specifying the formats, locations, etc of the reports to generate.

  • date (String)

    A string containing the date (YYYY-MM-DD) that the report ends on. E.g., for Jan 1-Feb 1 2017, you’d pass 2017-02-01.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/how_is.rb', line 52

def self.from_config(config, date)
  report = Report.new(config["repository"], date)
  report_data = (config["repository"], date)

  generated_reports =
    config["reports"].map { |format, report_config|
      # Sometimes report_data has unused keys, which generates a warning, but
      # we're okay with it, so we wrap it with silence_warnings {}.
      filename = silence_warnings { report_config["filename"] % report_data }
      file = File.join(report_config["directory"], filename)

      report_export = report.send("to_#{format}", report_config["frontmatter"])

      [file, report_export]
    }

  generated_reports.to_h
end

.from_hash(data) ⇒ HowIs

Given report data as a hash, create a new HowIs object (for generating other reports).

Parameters:

  • data (Hash)

    A hash containing report data.

Returns:

  • (HowIs)

    A HowIs object that can be used for generating other reports, treating the provided report data as a cache.



39
40
41
42
43
# File 'lib/how_is.rb', line 39

def self.from_hash(data)
  analysis = HowIs::Analysis.from_hash(data)

  new(analysis.repository, analysis)
end

.from_json(json) ⇒ HowIs

Given a JSON report, create a new HowIs object (for generating other reports).

Parameters:

  • json (String)

    A JSON report object.

Returns:

  • (HowIs)

    A HowIs object that can be used for generating other reports, treating the JSON report as a cache.



28
29
30
# File 'lib/how_is.rb', line 28

def self.from_json(json)
  from_hash(JSON.parse(json))
end

.githubObject



14
15
16
17
18
19
# File 'lib/how_is.rb', line 14

def self.github
  @@github ||=
    Github.new(auto_pagination: true) do |config|
      config.basic_auth = ENV["HOWIS_BASIC_AUTH"] if ENV["HOWIS_BASIC_AUTH"]
    end
end

.new(repository, date) ⇒ Object



10
11
12
# File 'lib/how_is.rb', line 10

def self.new(repository, date)
  Report.new(repository, date)
end

.supported_formatsArray<String>

Returns a list of possible export formats.

Returns:

  • (Array<String>)

    An array of the types of reports you can generate.



75
76
77
# File 'lib/how_is.rb', line 75

def self.supported_formats
  ["html", "json"]
end

.template(filename) ⇒ Object



79
80
81
82
83
84
# File 'lib/how_is.rb', line 79

def self.template(filename)
  dir  = File.expand_path("./how_is/templates/", __dir__)
  path = File.join(dir, filename)

  open(path).read
end