Class: Kriterion::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/kriterion/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Object

#find_section, #to_h

Constructor Details

#initialize(hash) ⇒ Resource

Returns a new instance of Resource.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/kriterion/resource.rb', line 20

def initialize(hash)
  @uuid             = hash['uuid'] || SecureRandom.uuid
  @title            = hash['title']
  @file             = hash['file']
  @line             = hash['line']
  @resource         = hash['resource']
  @resource_type    = hash['resource_type']
  @provider_used    = hash['provider_used']
  @containment_path = hash['containment_path']
  @tags             = hash['tags']
  @events           = hash['events'] || []
  @parent_uuid      = hash['parent_uuid']
  @unchanged_nodes  = hash['unchanged_nodes'] || []
end

Instance Attribute Details

#containment_pathObject (readonly)

Returns the value of attribute containment_path.



13
14
15
# File 'lib/kriterion/resource.rb', line 13

def containment_path
  @containment_path
end

#eventsObject

Returns the value of attribute events.



16
17
18
# File 'lib/kriterion/resource.rb', line 16

def events
  @events
end

#fileObject (readonly)

Returns the value of attribute file.



8
9
10
# File 'lib/kriterion/resource.rb', line 8

def file
  @file
end

#lineObject (readonly)

Returns the value of attribute line.



9
10
11
# File 'lib/kriterion/resource.rb', line 9

def line
  @line
end

#parent_uuidObject

Returns the value of attribute parent_uuid.



17
18
19
# File 'lib/kriterion/resource.rb', line 17

def parent_uuid
  @parent_uuid
end

#provider_usedObject (readonly)

Returns the value of attribute provider_used.



12
13
14
# File 'lib/kriterion/resource.rb', line 12

def provider_used
  @provider_used
end

#resourceObject (readonly)

Returns the value of attribute resource.



10
11
12
# File 'lib/kriterion/resource.rb', line 10

def resource
  @resource
end

#resource_typeObject (readonly)

Returns the value of attribute resource_type.



11
12
13
# File 'lib/kriterion/resource.rb', line 11

def resource_type
  @resource_type
end

#tagsObject (readonly)

Returns the value of attribute tags.



14
15
16
# File 'lib/kriterion/resource.rb', line 14

def tags
  @tags
end

#titleObject (readonly)

Returns the value of attribute title.



7
8
9
# File 'lib/kriterion/resource.rb', line 7

def title
  @title
end

#unchanged_nodesObject

Returns the value of attribute unchanged_nodes.



18
19
20
# File 'lib/kriterion/resource.rb', line 18

def unchanged_nodes
  @unchanged_nodes
end

#uuidObject (readonly)

Returns the value of attribute uuid.



6
7
8
# File 'lib/kriterion/resource.rb', line 6

def uuid
  @uuid
end

Instance Method Details

#==(other) ⇒ Object



35
36
37
# File 'lib/kriterion/resource.rb', line 35

def ==(other)
  other.resource == resource
end

#complianceObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/kriterion/resource.rb', line 39

def compliance
  compliant     = unchanged_nodes.count
  non_compliant = events.group_by(&:certname).count
  total         = compliant + non_compliant
  percentage    = if total.zero?
                    0
                  else
                    compliant / total
                  end

  {
    'compliant' => events.empty?,
    'events'    => {
      'percentage'    => percentage,
      'compliant'     => compliant,
      'non_compliant' => non_compliant,
      'total'         => total
    }
  }
end