Sha256: 544882333552c5995d2148a3b861aaa8288a4e43b0005e0a2ded626650935b31

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

module Lutaml
  module XMI
    class GeneralizationAttributeDrop < Liquid::Drop
      def initialize(attr, upper_klass, gen_name, guidance = nil) # rubocop:disable Lint/MissingSuper
        @attr = attr
        @upper_klass = upper_klass
        @gen_name = gen_name
        @guidance = guidance
      end

      def id
        @attr[:id]
      end

      def name
        @attr[:name]
      end

      def type
        @attr[:type]
      end

      def xmi_id
        @attr[:xmi_id]
      end

      def is_derived
        @attr[:is_derived]
      end

      def cardinality
        ::Lutaml::XMI::CardinalityDrop.new(@attr[:cardinality])
      end

      def definition
        @attr[:definition]
      end

      def association
        @attr[:association]
      end

      def has_association?
        !!@attr[:association]
      end

      def type_ns
        @attr[:type_ns]
      end

      def upper_klass
        @upper_klass
      end

      def gen_name
        @gen_name
      end

      def name_ns
        name_ns = case @attr[:type_ns]
                  when "core", "gml"
                    upper_klass
                  else
                    @attr[:type_ns]
                  end

        name_ns = upper_klass if name_ns.nil?
        name_ns
      end

      def used?
        if @guidance
          col_name = "#{name_ns}:#{name}"
          attr = @guidance["attributes"].find { |a| a["name"] == col_name }
          return attr["used"] if attr
        end

        true
      end

      def guidance
        if @guidance
          col_name = "#{name_ns}:#{name}"
          attr = @guidance["attributes"].find { |a| a["name"] == col_name }

          attr["guidance"] if attr
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lutaml-0.9.19 lib/lutaml/xmi/liquid_drops/generalization_attribute_drop.rb
lutaml-0.9.18 lib/lutaml/xmi/liquid_drops/generalization_attribute_drop.rb