Class: Oscal::WithId
- Includes:
- Serializer
- Defined in:
- lib/oscal/with_id.rb
Constant Summary collapse
- KEY =
%i(val)
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ WithId
constructor
A new instance of WithId.
Methods included from Serializer
included, #to_h, #to_json, #to_xml, #to_yaml
Methods inherited from BaseClass
Constructor Details
#initialize(options = {}) ⇒ WithId
Returns a new instance of WithId.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/oscal/with_id.rb', line 22 def initialize( = {}) klass = self.class unless .is_a? Hash = { KEY.first.to_s => } end .each_pair.each do |key, val| key_name = key.gsub("-", "_") unless KEY.include?(key_name.to_sym) raise UnknownAttributeError.new("Unknown key `#{key}` in #{klass.name}") end send("#{key_name}=", val) end end |