Class: ForemanOpenscap::ArfReportStatusCalculator

Inherits:
Object
  • Object
show all
Defined in:
app/services/foreman_openscap/arf_report_status_calculator.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ArfReportStatusCalculator

Returns a new instance of ArfReportStatusCalculator.



3
4
5
6
# File 'app/services/foreman_openscap/arf_report_status_calculator.rb', line 3

def initialize(options = {})
  @counters   = options[:counters]  || {}
  @raw_status = options[:bit_field] || 0
end

Instance Method Details

#calculateObject



8
9
10
11
12
13
14
15
16
# File 'app/services/foreman_openscap/arf_report_status_calculator.rb', line 8

def calculate
  @raw_status = 0
  counters.each do |type, value|
    value = value.to_i
    value = ArfReport::MAX if value > ArfReport::MAX
    @raw_status |= value << (ArfReport::BIT_NUM * ArfReport::METRIC.index(type))
  end
  raw_status
end

#statusObject



18
19
20
21
22
23
24
25
26
27
# File 'app/services/foreman_openscap/arf_report_status_calculator.rb', line 18

def status
  @status ||= begin
    calculate if raw_status == 0
    counters = Hash.new(0)
    ArfReport::METRIC.each do |m|
      counters[m] = (raw_status || 0) >> (ArfReport::BIT_NUM * ArfReport::METRIC.index(m)) & ArfReport::MAX
    end
    counters
  end
end

#status_of(counter) ⇒ Object

Raises:

  • (Foreman::Exception)


29
30
31
32
# File 'app/services/foreman_openscap/arf_report_status_calculator.rb', line 29

def status_of(counter)
  raise(Foreman::Exception.new(N_("invalid type %s"), counter)) unless ArfReport::METRIC.include?(counter)
  status[counter]
end