Sha256: 02429f7bf91c078ef23473c5ff8e6f41c22d377c93d26fcde72f8601a69adf02

Contents?: true

Size: 1.76 KB

Versions: 2

Compression:

Stored size: 1.76 KB

Contents

module Stepmod
  module Utils
    module Converters
      class StepmodExtDescription < ReverseAdoc::Converters::Base
        def convert(node, state = {})
          state = state.merge(schema_name: node["linkend"])
          linkend = node["linkend"].split(".")

          # We only want ENTITY entries, not their attributes
          # https://github.com/metanorma/iso-10303-2/issues/36#issuecomment-841300092
          return nil if linkend.length != 2

          child_text = treat_children(node, state).strip
          return nil if child_text.empty?

          # Unless the first paragraph ends with "between" and is followed by a
          # list, don't split
          first_child = child_text.split("\n").first

          unless (
            first_child =~ /between:?\s*\Z/ ||
            first_child =~ /include:?\s*\Z/ ||
            first_child =~ /of:?\s*\Z/ ||
            first_child =~ /[:;]\s*\Z/
            ) &&
            child_text =~ /\n\n\*/

            # Only taking the first paragraph of the definition
            child_text = first_child
          end

          # # Only taking the first sentence
          # if child_text.contains?(".")
          #   child_text = child_text.split(".").first
          # end

          domain =  case linkend.first
                    when /_mim$/, /_arm$/
                      "STEP module"
                    # when /_schema$/
                    else
                      "STEP resource"
                    end

          <<~TEMPLATE
            === #{linkend.last}

            #{domain ? "domain:[#{domain}]" : ''}

            #{child_text}
          TEMPLATE
        end
      end
      ReverseAdoc::Converters.register :ext_description,
                                       StepmodExtDescription.new
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stepmod-utils-0.3.11 lib/stepmod/utils/converters/stepmod_ext_description.rb
stepmod-utils-0.3.10 lib/stepmod/utils/converters/stepmod_ext_description.rb