Sha256: 9c06fb9ebe39724174d1ad2ffc5a980531ff762535f5e0bf17a3d74263ef769c

Contents?: true

Size: 823 Bytes

Versions: 46

Compression:

Stored size: 823 Bytes

Contents

# frozen_string_literal: true

module Lutaml
  module Uml
    module HasMembers
      class UnknownMemberTypeError < StandardError; end

      # TODO: move to Parslet::Transform
      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

      def associtaion_type(type)
        return type if respond_to?("#{type}=")

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

Version data entries

46 entries across 46 versions & 2 rubygems

Version Path
lutaml-0.9.5 lib/lutaml/uml/has_members.rb
lutaml-0.9.4 lib/lutaml/uml/has_members.rb
lutaml-0.9.3 lib/lutaml/uml/has_members.rb
lutaml-0.9.2 lib/lutaml/uml/has_members.rb
lutaml-0.9.1 lib/lutaml/uml/has_members.rb
lutaml-0.9.0 lib/lutaml/uml/has_members.rb
lutaml-0.8.1 lib/lutaml/uml/has_members.rb
lutaml-0.8.0 lib/lutaml/uml/has_members.rb
lutaml-uml-0.4.3 lib/lutaml/uml/has_members.rb
lutaml-uml-0.4.1 lib/lutaml/uml/has_members.rb
lutaml-uml-0.4.0 lib/lutaml/uml/has_members.rb
lutaml-uml-0.3.2 lib/lutaml/uml/has_members.rb
lutaml-uml-0.3.1 lib/lutaml/uml/has_members.rb
lutaml-uml-0.3.0 lib/lutaml/uml/has_members.rb
lutaml-uml-0.2.12 lib/lutaml/uml/has_members.rb
lutaml-uml-0.2.10 lib/lutaml/uml/has_members.rb
lutaml-uml-0.2.9 lib/lutaml/uml/has_members.rb
lutaml-uml-0.2.8 lib/lutaml/uml/has_members.rb
lutaml-uml-0.2.7 lib/lutaml/uml/has_members.rb
lutaml-uml-0.2.6 lib/lutaml/uml/has_members.rb