Sha256: 392d488e17c61febb47c24438b8ad174131096bb913f2ccd5b2c261c8f78db6b

Contents?: true

Size: 859 Bytes

Versions: 1

Compression:

Stored size: 859 Bytes

Contents

module Oscal
  class Group
    KEYS = %i(id class title controls props parts groups)
    attr_accessor *KEYS

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

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

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

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

        val = case key_name
        when 'groups'
          Group.wrap(val)
        when 'params'
          Parameter.wrap(val)
        when 'props'
          Property.wrap(val)
        when 'parts'
          Part.wrap(val)
        else
          val
        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/group.rb