Class: Oscal::V1_2_1::Map

Inherits:
Base
  • Object
show all
Defined in:
lib/oscal/v1_2_1/all_models.rb

Instance Method Summary collapse

Methods inherited from Base

lutaml_default_register

Instance Method Details

#json_assembly_soa_from_confidence_score_confidence_score(instance, value) ⇒ Object



10353
10354
10355
10356
10357
10358
10359
10360
10361
# File 'lib/oscal/v1_2_1/all_models.rb', line 10353

def json_assembly_soa_from_confidence_score_confidence_score(instance, value)
  items = case value
          when Hash then [value]
          when Array then value
          else return
          end
  parsed = items.map { |item| Oscal::V1_2_1::ConfidenceScore.of_json(item.is_a?(Hash) ? item : {}) }
  instance.instance_variable_set(:@confidence_score, parsed)
end

#json_assembly_soa_to_confidence_score_confidence_score(instance, doc) ⇒ Object



10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
# File 'lib/oscal/v1_2_1/all_models.rb', line 10339

def json_assembly_soa_to_confidence_score_confidence_score(instance, doc)
  current = instance.instance_variable_get(:@confidence_score)
  if current.is_a?(Array)
    result = current.map do |item|
      if item.is_a?(Lutaml::Model::Serializable)
        Oscal::V1_2_1::ConfidenceScore.as_json(item)
      else
        item
      end
    end
    doc["confidence-score"] = result.length == 1 ? result.first : result
  end
end

#json_from_coverage_coverage(instance, value) ⇒ Object



10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
# File 'lib/oscal/v1_2_1/all_models.rb', line 10258

def json_from_coverage_coverage(instance, value)
  if value.is_a?(Array)
    parsed = value.map { |v| Oscal::V1_2_1::Coverage.of_json(v) }
    instance.instance_variable_set(:@coverage, parsed)
  elsif value.is_a?(Hash)
    if value.empty?
      inst = Oscal::V1_2_1::Coverage.new(content: "")
      instance.instance_variable_set(:@coverage, inst)
    else
      instance.instance_variable_set(:@coverage, Oscal::V1_2_1::Coverage.of_json(value))
    end
  elsif value
    instance.instance_variable_set(:@coverage, Oscal::V1_2_1::Coverage.of_json(value))
  end
end

#json_from_remarks_remarks(instance, value) ⇒ Object



10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
# File 'lib/oscal/v1_2_1/all_models.rb', line 10288

def json_from_remarks_remarks(instance, value)
  if value.is_a?(Array)
    parsed = value.map { |v| Oscal::V1_2_1::Remarks.of_json(v) }
    instance.instance_variable_set(:@remarks, parsed)
  elsif value.is_a?(Hash)
    if value.empty?
      inst = Oscal::V1_2_1::Remarks.new(content: "")
      instance.instance_variable_set(:@remarks, inst)
    else
      instance.instance_variable_set(:@remarks, Oscal::V1_2_1::Remarks.of_json(value))
    end
  elsif value
    instance.instance_variable_set(:@remarks, Oscal::V1_2_1::Remarks.of_json(value))
  end
end

#json_soa_from_relationship_relationship(instance, value) ⇒ Object



10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
# File 'lib/oscal/v1_2_1/all_models.rb', line 10318

def json_soa_from_relationship_relationship(instance, value)
  items = case value
          when Hash then [value]
          when Array then value
          when String then [value]
          else return
          end
  parsed = items.map { |item| item.is_a?(Hash) ? item : item }
  instance.instance_variable_set(:@relationship, parsed)
end

#json_soa_to_relationship_relationship(instance, doc) ⇒ Object



10329
10330
10331
10332
10333
10334
10335
10336
10337
# File 'lib/oscal/v1_2_1/all_models.rb', line 10329

def json_soa_to_relationship_relationship(instance, doc)
  current = instance.instance_variable_get(:@relationship)
  if current.is_a?(Array)
    result = current.map do |item|
      item.respond_to?(:to_h) ? item.to_h : item
    end
    doc["relationship"] = result.length == 1 ? result.first : result
  end
end

#json_to_coverage_coverage(instance, doc) ⇒ Object



10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
# File 'lib/oscal/v1_2_1/all_models.rb', line 10274

def json_to_coverage_coverage(instance, doc)
  current = instance.instance_variable_get(:@coverage)
  if current.is_a?(Array)
    doc["coverage"] = current.map { |item| item.respond_to?(:content) ? item.content : item }
  elsif current
    if current.is_a?(Lutaml::Model::Serializable)
      doc["coverage"] = Oscal::V1_2_1::Coverage.as_json(current)
    else
      val = current.respond_to?(:content) ? current.content : current
      doc["coverage"] = val
    end
  end
end

#json_to_remarks_remarks(instance, doc) ⇒ Object



10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
# File 'lib/oscal/v1_2_1/all_models.rb', line 10304

def json_to_remarks_remarks(instance, doc)
  current = instance.instance_variable_get(:@remarks)
  if current.is_a?(Array)
    doc["remarks"] = current.map { |item| item.respond_to?(:content) ? item.content : item }
  elsif current
    if current.is_a?(Lutaml::Model::Serializable)
      doc["remarks"] = Oscal::V1_2_1::Remarks.as_json(current)
    else
      val = current.respond_to?(:content) ? current.content : current
      doc["remarks"] = val
    end
  end
end

#validate_occurrencesObject



10363
10364
10365
# File 'lib/oscal/v1_2_1/all_models.rb', line 10363

def validate_occurrences
  Metaschema::ConstraintValidator.validate_occurrences(self, self.class.instance_variable_get(:@occurrence_constraints))
end