blob: 6d45096765dfa318ac7e02f7240aca0bcca2a780 (
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
  | 
class ComplianceCheckResult < ActiveRecord::Base
  scope :warning, -> { where severity: 'warning' }
  scope :error, -> { where severity: 'error' }
  scope :improvment, -> { where severity: 'improvment' }
  scope :ok, -> { where status: 'ok' }
  scope :nok, -> { where status: 'nok' }
  scope :na, -> { where status: 'na' }  
  attr_accessible :violation_count
  belongs_to :compliance_check_task
  validates_presence_of :rule_code
  validates_inclusion_of :severity, :in => %w{warning error improvment}
  validates_inclusion_of :status, :in => %w{na ok nok}
  serialize :detail, JSON
  def indice
    return nil unless rule_code
    rule_code.match( /\d+-\w+-\w+-(\d+)/ )[1].to_i
  end
  def data_type
    return nil unless rule_code
    rule_code.match( /\d+-\w+-(\w+)-\d+/ )[1]
  end
  def format
    return nil unless rule_code
    rule_code.match( /\d+-(\w+)-\w+-\d+/ )[1]
  end
  def level
    return nil unless rule_code
    rule_code.match( /(\d+)-\w+-\w+-\d+/ )[1].to_i
  end
  def rule_code_formatted
    rule_code.gsub("-", "_").downcase if rule_level
  end
end
  |