Sha256: 58acf32a2419238446cd7c2a30724f9432319338b24f553b9a83cb27d4668d3a

Contents?: true

Size: 1.67 KB

Versions: 6

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

require_relative "./lutaml_uml_class_preprocessor.rb"

module Metanorma
  module Plugin
    module Lutaml
      #  Macro for quick rendering of datamodel attributes/values table
      #  @example [lutaml_uml_attributes_table,path/to/lutaml,EntityName]
      class LutamlUmlAttributesTablePreprocessor < LutamlUmlClassPreprocessor
        MACRO_REGEXP =
          /\[lutaml_uml_attributes_table,([^,]+),?([^,]+),?(.+?)?\]/

        # rubocop:disable Layout/IndentHeredoc
        def template(options)
          skip_headers = options[:skip_headers]

          <<~TEMPLATE
          #{"=== {{ definition.name }}" unless skip_headers}
          {{ definition.definition }}

          {% if definition.attributes %}
          {% if definition.keyword == 'enumeration' %}
          .{{ definition.name }} values
          |===
          |Name |Definition

          {% for item in definition.attributes %}
          |{{ item.name }} |{{ item.definition }}
          {% endfor %}
          |===
          {% else %}
          .{{ definition.name }} attributes
          |===
          |Name |Definition |Mandatory / Optional / Conditional |Max Occur |Data Type

          {% for item in definition.attributes %}
          |{{ item.name }} |{% if item.definition %}{{ item.definition }}{% endif %} |{% if item.cardinality.min == "0" %}O{% else %}M{% endif %} |{% if item.cardinality.max == "*" %}N{% else %}1{% endif %} |{% if item.origin %}<<{{ item.origin }}>>{% endif %} `{{ item.type }}`
          {% endfor %}
          |===
          {% endif %}
          {% endif %}

          TEMPLATE
        end
        # rubocop:enable Layout/IndentHeredoc
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
metanorma-plugin-lutaml-0.4.20 lib/metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor.rb
metanorma-plugin-lutaml-0.4.19 lib/metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor.rb
metanorma-plugin-lutaml-0.4.18.2 lib/metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor.rb
metanorma-plugin-lutaml-0.4.18.1 lib/metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor.rb
metanorma-plugin-lutaml-0.4.18 lib/metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor.rb
metanorma-plugin-lutaml-0.4.17 lib/metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor.rb