Class: PmdTester::PmdReportDetail

Inherits:
Object
  • Object
show all
Defined in:
lib/pmdtester/pmd_report_detail.rb

Overview

This class represents all details about report of pmd

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(execution_time: 0, timestamp: '', working_dir: Dir.getwd, exit_code: nil) ⇒ PmdReportDetail

Returns a new instance of PmdReportDetail.



13
14
15
16
17
18
# File 'lib/pmdtester/pmd_report_detail.rb', line 13

def initialize(execution_time: 0, timestamp: '', working_dir: Dir.getwd, exit_code: nil)
  @execution_time = execution_time
  @timestamp = timestamp
  @working_dir = working_dir
  @exit_code = exit_code.nil? ? '?' : exit_code.to_s
end

Instance Attribute Details

#execution_timeObject

Returns the value of attribute execution_time.



8
9
10
# File 'lib/pmdtester/pmd_report_detail.rb', line 8

def execution_time
  @execution_time
end

#exit_codeObject

Returns the value of attribute exit_code.



11
12
13
# File 'lib/pmdtester/pmd_report_detail.rb', line 11

def exit_code
  @exit_code
end

#timestampObject

Returns the value of attribute timestamp.



9
10
11
# File 'lib/pmdtester/pmd_report_detail.rb', line 9

def timestamp
  @timestamp
end

#working_dirObject

Returns the value of attribute working_dir.



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

def working_dir
  @working_dir
end

Class Method Details

.convert_seconds(seconds) ⇒ Object

convert seconds into HH::MM::SS



54
55
56
# File 'lib/pmdtester/pmd_report_detail.rb', line 54

def self.convert_seconds(seconds)
  Time.at(seconds.abs).utc.strftime('%H:%M:%S')
end

.create(execution_time: 0, timestamp: '', working_dir: Dir.getwd, exit_code: nil, report_info_path:) ⇒ Object



46
47
48
49
50
51
# File 'lib/pmdtester/pmd_report_detail.rb', line 46

def self.create(execution_time: 0, timestamp: '', working_dir: Dir.getwd, exit_code: nil, report_info_path:)
  detail = PmdReportDetail.new(execution_time: execution_time, timestamp: timestamp,
                               working_dir: working_dir, exit_code: exit_code)
  detail.save(report_info_path)
  detail
end

.load(report_info_path) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/pmdtester/pmd_report_detail.rb', line 32

def self.load(report_info_path)
  if File.exist?(report_info_path)
    hash = JSON.parse(File.read(report_info_path), symbolize_names: true)
    PmdReportDetail.new(**hash)
  else
    PmdTester.logger.warn("#{report_info_path} doesn't exist")
    PmdReportDetail.new
  end
end

Instance Method Details

#format_execution_timeObject



42
43
44
# File 'lib/pmdtester/pmd_report_detail.rb', line 42

def format_execution_time
  self.class.convert_seconds(@execution_time)
end

#save(report_info_path) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pmdtester/pmd_report_detail.rb', line 20

def save(report_info_path)
  hash = {
    execution_time: @execution_time,
    timestamp: @timestamp,
    working_dir: @working_dir,
    exit_code: @exit_code
  }
  file = File.new(report_info_path, 'w')
  file.puts JSON.generate(hash)
  file.close
end