Sha256: d4b40acf79243f0ae1407d9d194e556c0cd4358b05c1470e27301847878a7f09

Contents?: true

Size: 1.1 KB

Versions: 16

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

16 entries across 16 versions & 1 rubygems

Version Path
foreman_openscap-0.7.13 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-0.7.12 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-0.7.11 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-0.7.10 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-0.8.3 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-0.7.9 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-0.7.8 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-0.7.7 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-0.8.2 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-0.7.6 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-0.8.1 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-0.7.5 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-0.8.0 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-0.7.4 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-0.7.3 app/services/foreman_openscap/arf_report_status_calculator.rb
foreman_openscap-0.7.2 app/services/foreman_openscap/arf_report_status_calculator.rb