module Lutaml::Uml::HasMembers

Public Instance Methods

members=(value) click to toggle source

TODO: move to Parslet::Transform

# File lib/lutaml/uml/has_members.rb, line 9
def members=(value)
  value.group_by { |member| member.keys.first }
    .each do |(type, group)|
      attribute_value = group.map(&:values).flatten
      if attribute_value.length == 1 && !attribute_value.first.is_a?(Hash)
        next public_send("#{associtaion_type(type)}=", attribute_value.first)
      end

      public_send("#{associtaion_type(type)}=", attribute_value)
    end
end

Private Instance Methods

associtaion_type(type) click to toggle source
# File lib/lutaml/uml/has_members.rb, line 23
def associtaion_type(type)
  return type if respond_to?("#{type}=")

  raise(UnknownMemberTypeError, "Unknown member type: #{type}")
end