aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/compliance_check_result.rb
blob: cd956a021240200fef87b76306fd320a1b7f162f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class ComplianceCheckResult
  extend ActiveModel::Naming
  extend ActiveModel::Translation
  include ActiveModel::Model

  attr_accessor :datas

  def initialize(response)
    @datas = response.validation_report
  end

  def tests?
    datas.tests?
  end

  def ok_error
    all('ok', 'error')
  end

  def nok_error
    all('nok', 'error')
  end

  def na_error
    all('uncheck', 'error')
  end

  def ok_warning
    all('ok', 'warning')
  end

  def nok_warning
    all('nok', 'warning')
  end

  def na_warning
    all('uncheck', 'warning')
  end

  def all(status, severity)
    tests? ? tests.select { |test| test.result == status.downcase && test.severity == severity.downcase } : []
  end

  def tests
    @tests ||= tests? ? datas.tests.map{ |test| Test.new(test) } : []
  end

  class Test
    attr_reader :options

    def initialize( options )
      @options = options
    end

    def test_id
      options.test_id if options.test_id?
    end

    def severity
      options.severity.downcase if options.severity?
    end

    def result
      options.result.downcase if options.result?
    end

    def errors
      options.errors if options.errors?
    end

    def error_count
      options.error_count if options.error_count?
    end
  end

end