Class: ForemanOpenscap::ArfReportStatusCalculator
- Inherits:
-
Object
- Object
- ForemanOpenscap::ArfReportStatusCalculator
- Defined in:
- app/services/foreman_openscap/arf_report_status_calculator.rb
Instance Method Summary collapse
- #calculate ⇒ Object
-
#initialize(options = {}) ⇒ ArfReportStatusCalculator
constructor
A new instance of ArfReportStatusCalculator.
- #status ⇒ Object
- #status_of(counter) ⇒ Object
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( = {}) @counters = [:counters] || {} @raw_status = [:bit_field] || 0 end |
Instance Method Details
#calculate ⇒ Object
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 |
#status ⇒ Object
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 |