Sha256: c3b7287f881894ac9cdca23644b4dac85a8e2e18ce44c0e9ab61e8e6a8f8bb67

Contents?: true

Size: 933 Bytes

Versions: 8

Compression:

Stored size: 933 Bytes

Contents

require "glossarist"

module Stepmod
  module Utils
    class Term < Glossarist::LocalizedConcept
      # Term acronym
      attr_accessor :acronym

      def to_mn_adoc
        mn_adoc = ["=== #{definition}"]
        mn_adoc << "\nalt:[#{acronym}]" if acronym
        mn_adoc << "\n\n#{designations.join(", ")}" if designations&.any?

        mn_adoc.join
      end

      class << self
        def from_h(hash)
          _, definition, acronym = treat_acronym(hash["definition"])

          hash["definition"] = definition
          hash["acronym"] = acronym.gsub(/\(|\)/, "") if acronym
          hash["designations"] = hash["synonyms"]

          super(hash.reject { |k, _| k == "synonyms" })
        end

        private

        def treat_acronym(term_def)
          return [nil, term_def.strip, nil] unless term_def.match?(/.+\(.+?\)$/)

          term_def.match(/(.+?)(\(.+\))$/).to_a
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
stepmod-utils-0.3.23 lib/stepmod/utils/term.rb
stepmod-utils-0.3.22 lib/stepmod/utils/term.rb
stepmod-utils-0.3.21 lib/stepmod/utils/term.rb
stepmod-utils-0.3.20 lib/stepmod/utils/term.rb
stepmod-utils-0.3.19 lib/stepmod/utils/term.rb
stepmod-utils-0.3.18 lib/stepmod/utils/term.rb
stepmod-utils-0.3.17 lib/stepmod/utils/term.rb
stepmod-utils-0.3.16 lib/stepmod/utils/term.rb