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.25 lib/lutaml/uml/has_members.rb
lutaml-0.9.24 lib/lutaml/uml/has_members.rb
lutaml-0.9.23 lib/lutaml/uml/has_members.rb
lutaml-0.9.22 lib/lutaml/uml/has_members.rb
lutaml-0.9.21 lib/lutaml/uml/has_members.rb
lutaml-0.9.20 lib/lutaml/uml/has_members.rb
lutaml-0.9.19 lib/lutaml/uml/has_members.rb
lutaml-0.9.18 lib/lutaml/uml/has_members.rb
lutaml-0.9.17 lib/lutaml/uml/has_members.rb
lutaml-0.9.16 lib/lutaml/uml/has_members.rb
lutaml-0.9.15 lib/lutaml/uml/has_members.rb
lutaml-0.9.14 lib/lutaml/uml/has_members.rb
lutaml-0.9.13 lib/lutaml/uml/has_members.rb
lutaml-0.9.12 lib/lutaml/uml/has_members.rb
lutaml-0.9.11 lib/lutaml/uml/has_members.rb
lutaml-0.9.10 lib/lutaml/uml/has_members.rb
lutaml-0.9.9 lib/lutaml/uml/has_members.rb
lutaml-0.9.8 lib/lutaml/uml/has_members.rb
lutaml-0.9.7 lib/lutaml/uml/has_members.rb
lutaml-0.9.6 lib/lutaml/uml/has_members.rb