Class: AbideDevUtils::Sce::Generate::CoverageReport::ReportOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/abide_dev_utils/sce/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, profile: nil, level: nil) ⇒ ReportOutput

Returns a new instance of ReportOutput.



170
171
172
173
174
175
176
177
178
# File 'lib/abide_dev_utils/sce/generate/coverage_report.rb', line 170

def initialize(benchmark, controls_in_resource_data, rules_in_map, profile: nil, level: nil)
  @benchmark = benchmark
  @controls_in_resource_data = controls_in_resource_data
  @rules_in_map = rules_in_map
  @profile = profile
  @level = level
  @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.



167
168
169
# File 'lib/abide_dev_utils/sce/generate/coverage_report.rb', line 167

def controls_in_resource_data
  @controls_in_resource_data
end

#rules_in_mapObject (readonly)

Returns the value of attribute rules_in_map.



167
168
169
# File 'lib/abide_dev_utils/sce/generate/coverage_report.rb', line 167

def rules_in_map
  @rules_in_map
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



167
168
169
# File 'lib/abide_dev_utils/sce/generate/coverage_report.rb', line 167

def timestamp
  @timestamp
end

#titleObject (readonly)

Returns the value of attribute title.



167
168
169
# File 'lib/abide_dev_utils/sce/generate/coverage_report.rb', line 167

def title
  @title
end

Instance Method Details

#benchmark_hashObject



221
222
223
224
225
226
227
228
229
# File 'lib/abide_dev_utils/sce/generate/coverage_report.rb', line 221

def benchmark_hash
  {
    title: @benchmark.title,
    version: @benchmark.version,
    framework: @benchmark.framework,
    profile: @profile || 'all',
    level: @level || 'all'
  }
end

#coverage_hashObject



231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/abide_dev_utils/sce/generate/coverage_report.rb', line 231

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



188
189
190
# File 'lib/abide_dev_utils/sce/generate/coverage_report.rb', line 188

def covered
  @covered ||= rules_in_map - uncovered
end

#covered_countObject



192
193
194
# File 'lib/abide_dev_utils/sce/generate/coverage_report.rb', line 192

def covered_count
  @covered_count ||= covered.length
end

#percentageObject



200
201
202
# File 'lib/abide_dev_utils/sce/generate/coverage_report.rb', line 200

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

#to_hObject



204
205
206
207
208
209
210
211
# File 'lib/abide_dev_utils/sce/generate/coverage_report.rb', line 204

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

#to_json(opts = nil) ⇒ Object



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

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

#to_yamlObject



217
218
219
# File 'lib/abide_dev_utils/sce/generate/coverage_report.rb', line 217

def to_yaml
  to_h.to_yaml
end

#total_countObject



196
197
198
# File 'lib/abide_dev_utils/sce/generate/coverage_report.rb', line 196

def total_count
  @total_count ||= rules_in_map.length
end

#uncoveredObject



180
181
182
# File 'lib/abide_dev_utils/sce/generate/coverage_report.rb', line 180

def uncovered
  @uncovered ||= rules_in_map - controls_in_resource_data
end

#uncovered_countObject



184
185
186
# File 'lib/abide_dev_utils/sce/generate/coverage_report.rb', line 184

def uncovered_count
  @uncovered_count ||= uncovered.length
end