Class: Kriterion::Resource
Instance Attribute Summary collapse
-
#containment_path ⇒ Object
readonly
Returns the value of attribute containment_path.
-
#events ⇒ Object
Returns the value of attribute events.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#parent_uuid ⇒ Object
Returns the value of attribute parent_uuid.
-
#provider_used ⇒ Object
readonly
Returns the value of attribute provider_used.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#resource_type ⇒ Object
readonly
Returns the value of attribute resource_type.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#unchanged_nodes ⇒ Object
Returns the value of attribute unchanged_nodes.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #compliance ⇒ Object
-
#initialize(hash) ⇒ Resource
constructor
A new instance of Resource.
Methods inherited from Object
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'] = hash['tags'] @events = hash['events'] || [] @parent_uuid = hash['parent_uuid'] @unchanged_nodes = hash['unchanged_nodes'] || [] end |
Instance Attribute Details
#containment_path ⇒ Object (readonly)
Returns the value of attribute containment_path.
13 14 15 |
# File 'lib/kriterion/resource.rb', line 13 def containment_path @containment_path end |
#events ⇒ Object
Returns the value of attribute events.
16 17 18 |
# File 'lib/kriterion/resource.rb', line 16 def events @events end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
8 9 10 |
# File 'lib/kriterion/resource.rb', line 8 def file @file end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
9 10 11 |
# File 'lib/kriterion/resource.rb', line 9 def line @line end |
#parent_uuid ⇒ Object
Returns the value of attribute parent_uuid.
17 18 19 |
# File 'lib/kriterion/resource.rb', line 17 def parent_uuid @parent_uuid end |
#provider_used ⇒ Object (readonly)
Returns the value of attribute provider_used.
12 13 14 |
# File 'lib/kriterion/resource.rb', line 12 def provider_used @provider_used end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
10 11 12 |
# File 'lib/kriterion/resource.rb', line 10 def resource @resource end |
#resource_type ⇒ Object (readonly)
Returns the value of attribute resource_type.
11 12 13 |
# File 'lib/kriterion/resource.rb', line 11 def resource_type @resource_type end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
14 15 16 |
# File 'lib/kriterion/resource.rb', line 14 def end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
7 8 9 |
# File 'lib/kriterion/resource.rb', line 7 def title @title end |
#unchanged_nodes ⇒ Object
Returns the value of attribute unchanged_nodes.
18 19 20 |
# File 'lib/kriterion/resource.rb', line 18 def unchanged_nodes @unchanged_nodes end |
#uuid ⇒ Object (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 |
#compliance ⇒ Object
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 |