Class: HowIs
- Inherits:
-
Object
- Object
- HowIs
- Includes:
- Contracts::Core
- Defined in:
- lib/how_is.rb,
lib/how_is/pulse.rb,
lib/how_is/report.rb,
lib/how_is/fetcher.rb,
lib/how_is/version.rb,
lib/how_is/analyzer.rb,
lib/how_is/report/html.rb,
lib/how_is/report/json.rb,
lib/how_is/contributions.rb,
lib/how_is/report/base_report.rb
Overview
HowIs control class used from the CLI tool.
Generates an analysis and has methods to build reports from it.
Defined Under Namespace
Classes: Analysis, Analyzer, BaseReport, CLI, Contributions, Fetcher, HtmlReport, JsonReport, Pulse, Report, UnsupportedExportFormat
Constant Summary collapse
- DEFAULT_FORMAT =
:html
- VERSION =
"18.1.0"
Class Method Summary collapse
-
.build_report(frontmatter, report_data, report) ⇒ Object
Combine the frontmatter, report data, and raw report into a report with frontmatter.
-
.can_export_to?(file) ⇒ Boolean
Returns whether or not the specified
file
can be exported to. -
.from_config(config, github: nil, report_class: nil) ⇒ Object
Generates a series of report files based on a config Hash.
-
.from_hash(data) ⇒ HowIs
Given report data as a hash, create a new HowIs object (for generating other reports).
-
.from_json(json) ⇒ HowIs
Given a JSON report, create a new HowIs object (for generating other reports).
- .generate_analysis(repository:, fetcher: Fetcher.new, analyzer: Analyzer.new, github: nil) ⇒ Object
- .generate_frontmatter(frontmatter, report_data) ⇒ Object
-
.supported_formats ⇒ Array<String>
Returns a list of possible export formats.
Instance Method Summary collapse
-
#initialize(repository, analysis = nil, **kw_args) ⇒ HowIs
constructor
Generate a HowIs instance, so you can generate reports.
-
#to_html ⇒ String
Generate an HTML report.
-
#to_json ⇒ String
Generate a JSON report.
Constructor Details
#initialize(repository, analysis = nil, **kw_args) ⇒ HowIs
Generate a HowIs instance, so you can generate reports.
30 31 32 33 34 35 36 |
# File 'lib/how_is.rb', line 30 def initialize(repository, analysis = nil, **kw_args) # If no Analysis is passed, generate one. analysis ||= HowIs.generate_analysis(repository: repository, **kw_args) # Used by to_html, to_json, etc. @analysis = analysis end |
Class Method Details
.build_report(frontmatter, report_data, report) ⇒ Object
Combine the frontmatter, report data, and raw report into a report with frontmatter.
186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/how_is.rb', line 186 def self.build_report(frontmatter, report_data, report) str = StringIO.new if frontmatter str.puts generate_frontmatter(frontmatter, report_data) str.puts "---" str.puts end str.puts report str.string end |
.can_export_to?(file) ⇒ Boolean
Returns whether or not the specified file
can be exported to.
94 95 96 97 |
# File 'lib/how_is.rb', line 94 def self.can_export_to?(file) # TODO: Check if the file is writable? supported_formats.include?(file.split(".").last) end |
.from_config(config, github: nil, report_class: nil) ⇒ Object
Generates a series of report files based on a config Hash.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/how_is.rb', line 148 def self.from_config(config, github: nil, report_class: nil) report_class ||= HowIs::Report date = Date.strptime(Time.now.to_i.to_s, "%s") friendly_date = date.strftime("%B %d, %y") analysis = HowIs.generate_analysis(repository: config["repository"], github: github) report_data = { repository: config["repository"], date: date, friendly_date: friendly_date, } generated_reports = {} config["reports"].map do |format, report_config| # Sometimes report_data has unused keys, which generates a warning, but # we're okay with it. filename = silence_warnings { report_config["filename"] % report_data } file = File.join(report_config["directory"], filename) report = report_class.export(analysis, format) result = build_report(report_config["frontmatter"], report_data, report) generated_reports[file] = result result end generated_reports end |
.from_hash(data) ⇒ HowIs
Given report data as a hash, create a new HowIs object (for generating other reports).
72 73 74 75 76 |
# File 'lib/how_is.rb', line 72 def self.from_hash(data) analysis = HowIs::Analyzer.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).
61 62 63 |
# File 'lib/how_is.rb', line 61 def self.from_json(json) from_hash(JSON.parse(json)) end |
.generate_analysis(repository:, fetcher: Fetcher.new, analyzer: Analyzer.new, github: nil) ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/how_is.rb', line 107 def self.generate_analysis(repository:, fetcher: Fetcher.new, analyzer: Analyzer.new, github: nil) raw_data = fetcher.call(repository, github) analysis = analyzer.call(raw_data) analysis end |
.generate_frontmatter(frontmatter, report_data) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/how_is.rb', line 124 def self.generate_frontmatter(frontmatter, report_data) frontmatter = convert_keys(frontmatter, :to_s) report_data = convert_keys(report_data, :to_sym) frontmatter = frontmatter.map { |k, v| # Sometimes report_data has unused keys, which generates a warning, but # we're okay with it. v = silence_warnings { v % report_data } [k, v] }.to_h YAML.dump(frontmatter) end |
.supported_formats ⇒ Array<String>
Returns a list of possible export formats.
83 84 85 86 |
# File 'lib/how_is.rb', line 83 def self.supported_formats report_constants = HowIs.constants.grep(/.Report/) - [:BaseReport] report_constants.map { |x| x.to_s.split("Report").first.downcase } end |