Class: Csa::Ccm::Control

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

Constant Summary collapse

ATTRIBS =
%i(
  id title specification questions
)

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Control

Returns a new instance of Control.



10
11
12
13
14
15
16
17
18
# File 'lib/csa/ccm/control.rb', line 10

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

  @questions ||= {}

  self
end

Instance Method Details

#to_file(filename) ⇒ Object



37
38
39
40
41
# File 'lib/csa/ccm/control.rb', line 37

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

#to_hashObject



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

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

    unless value.nil?

      if attrib == :questions
        value = value.values.map(&:to_hash)
      end

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