Class: AbideDevUtils::CEM::Generate::CoverageReport::ReportOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/abide_dev_utils/cem/generate/coverage_report.rb

Overview

Class manages organizing report data into various output formats

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(benchmark, controls_in_resource_data, rules_in_map) ⇒ ReportOutput

Returns a new instance of ReportOutput.



234
235
236
237
238
239
240
# File 'lib/abide_dev_utils/cem/generate/coverage_report.rb', line 234

def initialize(benchmark, controls_in_resource_data, rules_in_map)
  @benchmark = benchmark
  @controls_in_resource_data = controls_in_resource_data
  @rules_in_map = rules_in_map
  @timestamp = DateTime.now.iso8601
  @title = "Coverage Report for #{@benchmark.title_key}"
end

Instance Attribute Details

#controls_in_resource_dataObject (readonly)

Returns the value of attribute controls_in_resource_data.



231
232
233
# File 'lib/abide_dev_utils/cem/generate/coverage_report.rb', line 231

def controls_in_resource_data
  @controls_in_resource_data
end

#rules_in_mapObject (readonly)

Returns the value of attribute rules_in_map.



231
232
233
# File 'lib/abide_dev_utils/cem/generate/coverage_report.rb', line 231

def rules_in_map
  @rules_in_map
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



231
232
233
# File 'lib/abide_dev_utils/cem/generate/coverage_report.rb', line 231

def timestamp
  @timestamp
end

#titleObject (readonly)

Returns the value of attribute title.



231
232
233
# File 'lib/abide_dev_utils/cem/generate/coverage_report.rb', line 231

def title
  @title
end

Instance Method Details

#benchmark_hashObject



283
284
285
286
287
288
289
# File 'lib/abide_dev_utils/cem/generate/coverage_report.rb', line 283

def benchmark_hash
  {
    title: @benchmark.title,
    version: @benchmark.version,
    framework: @benchmark.framework,
  }
end

#coverage_hashObject



291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/abide_dev_utils/cem/generate/coverage_report.rb', line 291

def coverage_hash
  {
    total_count: total_count,
    uncovered_count: uncovered_count,
    uncovered: uncovered,
    covered_count: covered_count,
    covered: covered,
    percentage: percentage,
    controls_in_resource_data: controls_in_resource_data,
    rules_in_map: rules_in_map,
  }
end

#coveredObject



250
251
252
# File 'lib/abide_dev_utils/cem/generate/coverage_report.rb', line 250

def covered
  @covered ||= rules_in_map - uncovered
end

#covered_countObject



254
255
256
# File 'lib/abide_dev_utils/cem/generate/coverage_report.rb', line 254

def covered_count
  @covered_count ||= covered.length
end

#percentageObject



262
263
264
# File 'lib/abide_dev_utils/cem/generate/coverage_report.rb', line 262

def percentage
  @percentage ||= covered_count.to_f / total_count
end

#to_hObject



266
267
268
269
270
271
272
273
# File 'lib/abide_dev_utils/cem/generate/coverage_report.rb', line 266

def to_h
  {
    title: title,
    timestamp: timestamp,
    benchmark: benchmark_hash,
    coverage: coverage_hash,
  }
end

#to_json(opts = nil) ⇒ Object



275
276
277
# File 'lib/abide_dev_utils/cem/generate/coverage_report.rb', line 275

def to_json(opts = nil)
  JSON.generate(to_h, opts)
end

#to_yamlObject



279
280
281
# File 'lib/abide_dev_utils/cem/generate/coverage_report.rb', line 279

def to_yaml
  to_h.to_yaml
end

#total_countObject



258
259
260
# File 'lib/abide_dev_utils/cem/generate/coverage_report.rb', line 258

def total_count
  @total_count ||= rules_in_map.length
end

#uncoveredObject



242
243
244
# File 'lib/abide_dev_utils/cem/generate/coverage_report.rb', line 242

def uncovered
  @uncovered ||= rules_in_map - controls_in_resource_data
end

#uncovered_countObject



246
247
248
# File 'lib/abide_dev_utils/cem/generate/coverage_report.rb', line 246

def uncovered_count
  @uncovered_count ||= uncovered.length
end