Class: Csa::Ccm::ControlDomain

Inherits:
Object
  • Object
show all
Defined in:
lib/csa/ccm/control_domain.rb

Constant Summary collapse

ATTRIBS =
%i(
  id title controls
)

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ControlDomain

Returns a new instance of ControlDomain.



12
13
14
15
16
17
18
19
20
# File 'lib/csa/ccm/control_domain.rb', line 12

def initialize(options={})
  options.each_pair do |k,v|
    self.send("#{k}=", v)
  end

  @controls ||= {}

  self
end

Instance Method Details

#to_file(filename) ⇒ Object



38
39
40
41
42
# File 'lib/csa/ccm/control_domain.rb', line 38

def to_file(filename)
  File.open(filename,"w") do |file|
    file.write(to_hash.to_yaml)
  end
end

#to_hashObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/csa/ccm/control_domain.rb', line 22

def to_hash
  ATTRIBS.inject({}) do |acc, attrib|
    value = self.send(attrib)

    unless value.nil?
      if attrib == :controls
        value = value.values.map(&:to_hash)
      end

      acc.merge(attrib.to_s => value)
    else
      acc
    end
  end
end