blob: 399f406a9f65e50f4bab6ec291594ad9d338b3ff (
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
77
78
79
80
  | 
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
    tests? ? tests.select { |test| (test.result == "OK" && test.severity == "ERROR") } : []
  end
  
  def nok_error
    tests? ? tests.select { |test| (test.result == "NOK" && test.severity == "ERROR")} : []
  end
  
  def na_error
    tests? ? tests.select { |test| (test.result == "UNCHECK" && test.severity == "ERROR")} : []
  end
  def ok_warning
    tests? ? tests.select { |test| (test.result == "OK" && test.severity == "WARNING")} : []
  end
  
  def nok_warning
    tests? ? tests.select { |test| (test.result == "NOK" && test.severity == "WARNING")} : []
  end
  
  def na_warning
    tests? ? tests.select { |test| (test.result == "UNCHECK" && test.severity == "WARNING")} : []
  end
  
  def all(status, severity)
    tests? ? tests.select { |test| ( test.result == status && test.severity == severity ) } : []
  end
  def tests
    [].tap do |tests|
      datas.tests.each do |test|
        tests << Test.new(test)
      end if datas.tests?
    end
  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
  |