Module: Lutaml::Lml::DataProcessor::AttributeProcessing

Included in:
Lutaml::Lml::DataProcessor
Defined in:
lib/lutaml/lml/data_processor/attribute_processing.rb

Constant Summary collapse

EXCLUDED_PASS_THROUGH_KEYS =
%i[key value comments add attributes properties].freeze

Instance Method Summary collapse

Instance Method Details

#process_attributes(obj) ⇒ Object



9
10
11
12
13
14
# File 'lib/lutaml/lml/data_processor/attribute_processing.rb', line 9

def process_attributes(obj)
  case obj
  when Array then process_attributes_array(obj)
  when Hash then process_attributes_hash(obj)
  end
end

#process_attributes_array(obj) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/lutaml/lml/data_processor/attribute_processing.rb', line 16

def process_attributes_array(obj)
  return obj.map { |item| process_attributes(item) } unless single_key_hashes?(obj)

  obj.each_with_object({}) do |item, hash|
    hash[:properties] ||= []
    if item.key?(:properties)
      hash[:properties] << process_attributes(item[:properties])
    else
      hash.merge!(process_attributes(item))
    end
  end
end

#process_attributes_hash(obj) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/lutaml/lml/data_processor/attribute_processing.rb', line 29

def process_attributes_hash(obj)
  result = extract_name_and_value(obj)
  convert_instance_type(result)
  result[:extended] = !obj[:add].nil? if obj.key?(:add)
  apply_nested_attributes(result, obj)
  apply_remaining_keys(result, obj)
  result
end