Sha256: 06262f6926a0ee6532b4f65ba47390c188d0908c84b66ccf67141d7db70c92a8

Contents?: true

Size: 640 Bytes

Versions: 1

Compression:

Stored size: 640 Bytes

Contents

require_relative "serializer"

module Oscal
  class Part
    include Serializer

    KEY = %i(id name prose)
    attr_accessor *KEY
    attr_serializable *KEY

    def self.wrap(obj)
      return obj if obj.is_a? Part
      return Part.new(obj) unless obj.is_a? Array

      obj.map do |x|
        Part.wrap(x)
      end
    end

    def initialize(options={})
      options.each_pair.each do |key,val|
        key_name = key.gsub('-','_')

        unless KEY.include?(key_name.to_sym)
          raise UnknownAttributeError.new("Unknown key `#{key}` in Part")
        end

        self.send("#{key_name}=", val)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
oscal-0.1.0 lib/oscal/part.rb