Class: Oscal::V1_2_1::ConfidenceScore

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_from_percentage_percentage(instance, value) ⇒ Object



10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
# File 'lib/oscal/v1_2_1/all_models.rb', line 10403

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

#json_to_percentage_percentage(instance, doc) ⇒ Object



10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
# File 'lib/oscal/v1_2_1/all_models.rb', line 10419

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