Sha256: f039096a9174106070c7caf41cbc58c91d6a57b23bcbeb7939ccecadc7c0dbeb

Contents?: true

Size: 1.1 KB

Versions: 74

Compression:

Stored size: 1.1 KB

Contents

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

    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

    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

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

    ArfReport::METRIC.each do |method|
      define_method method do
        status_of(method)
      end
    end

    private

    attr_accessor :raw_status, :counters
  end
end

Version data entries

74 entries across 74 versions & 1 rubygems

Version Path
foreman_openscap-10.0.2 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-10.0.1 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-10.0.0 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-9.0.4 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-9.0.3 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-9.0.2 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-9.0.1 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-9.0.0 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-8.0.0 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-7.1.1 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-7.1.0 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-7.0.0 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-6.0.0 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-5.2.3 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-5.2.2 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-5.1.1 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-5.2.1 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-5.2.0 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-5.1.0 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-5.0.0 app/services/foreman_openscap/arf_report_status_calculator.rb