Class: Csa::Ccm::Answer
- Inherits:
-
Object
- Object
- Csa::Ccm::Answer
- Defined in:
- lib/csa/ccm/answer.rb
Constant Summary collapse
- ATTRIBS =
%i( id content control-id question-id notes )
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Answer
constructor
A new instance of Answer.
- #to_hash ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Answer
Returns a new instance of Answer.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/csa/ccm/answer.rb', line 13 def initialize(={}) @examples = [] @notes = [] # puts "options #{options.inspect}" .each_pair do |k, v| next unless v case k when /^example/ @examples << v when /^note/ @notes << v else # puts"Key #{k}" key = k.gsub("-", "_") self.send("#{key}=", v) end end self end |
Instance Method Details
#to_hash ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/csa/ccm/answer.rb', line 35 def to_hash ATTRIBS.inject({}) do |acc, attrib| value = self.send(attrib) unless value.nil? acc.merge(attrib.to_s => value) else acc end end end |