Class: DocHealth::Report
- Inherits:
-
Object
- Object
- DocHealth::Report
- Defined in:
- lib/doc_health/report.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #generate ⇒ Object
- #generate_csv(rows) ⇒ Object
-
#initialize(options) ⇒ Report
constructor
A new instance of Report.
- #print_table(headers, rows) ⇒ Object
Constructor Details
#initialize(options) ⇒ Report
Returns a new instance of Report.
11 12 13 14 |
# File 'lib/doc_health/report.rb', line 11 def initialize() @path = [:path] || Dir.pwd @generate_csv = [:csv] || false end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/doc_health/report.rb', line 9 def path @path end |
Instance Method Details
#generate ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/doc_health/report.rb', line 16 def generate unless File.directory?(path) puts "The path is invalid." return end rows = Git.new(path). if @generate_csv generate_csv(rows) puts "📋 CSV generated" return end print_table(["File", "Last Commit (EST)"], rows) end |
#generate_csv(rows) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/doc_health/report.rb', line 38 def generate_csv(rows) CSV.open("doc_health_report.csv", "wb") do |csv| csv << ["File", "Last Commit (EST)"] rows.each { |row| csv << row } end end |
#print_table(headers, rows) ⇒ Object
33 34 35 36 |
# File 'lib/doc_health/report.rb', line 33 def print_table(headers, rows) table = Terminal::Table.new headings: headers, rows: rows puts table end |