Class: DocHealth::Report

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options)
  @path = options[:path] || Dir.pwd
  @generate_csv = options[:csv] || false
end

Instance Attribute Details

#pathObject (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

#generateObject



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).file_commit_author

  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


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