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

Inherits:
Object
  • Object
show all
Defined in:
lib/abide_dev_utils/cem/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.



216
217
218
219
220
221
222
# File 'lib/abide_dev_utils/cem/coverage_report.rb', line 216

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.



213
214
215
# File 'lib/abide_dev_utils/cem/coverage_report.rb', line 213

def controls_in_resource_data
  @controls_in_resource_data
end

#rules_in_mapObject (readonly)

Returns the value of attribute rules_in_map.



213
214
215
# File 'lib/abide_dev_utils/cem/coverage_report.rb', line 213

def rules_in_map
  @rules_in_map
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



213
214
215
# File 'lib/abide_dev_utils/cem/coverage_report.rb', line 213

def timestamp
  @timestamp
end

#titleObject (readonly)

Returns the value of attribute title.



213
214
215
# File 'lib/abide_dev_utils/cem/coverage_report.rb', line 213

def title
  @title
end

Instance Method Details

#benchmark_hashObject



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

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

#coverage_hashObject



273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/abide_dev_utils/cem/coverage_report.rb', line 273

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



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

def covered
  @covered ||= rules_in_map - uncovered
end

#covered_countObject



236
237
238
# File 'lib/abide_dev_utils/cem/coverage_report.rb', line 236

def covered_count
  @covered_count ||= covered.length
end

#percentageObject



244
245
246
# File 'lib/abide_dev_utils/cem/coverage_report.rb', line 244

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

#to_hObject



248
249
250
251
252
253
254
255
# File 'lib/abide_dev_utils/cem/coverage_report.rb', line 248

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

#to_json(opts = nil) ⇒ Object



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

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

#to_yamlObject



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

def to_yaml
  to_h.to_yaml
end

#total_countObject



240
241
242
# File 'lib/abide_dev_utils/cem/coverage_report.rb', line 240

def total_count
  @total_count ||= rules_in_map.length
end

#uncoveredObject



224
225
226
# File 'lib/abide_dev_utils/cem/coverage_report.rb', line 224

def uncovered
  @uncovered ||= rules_in_map - controls_in_resource_data
end

#uncovered_countObject



228
229
230
# File 'lib/abide_dev_utils/cem/coverage_report.rb', line 228

def uncovered_count
  @uncovered_count ||= uncovered.length
end