Sha256: 6300f173a3636b6d16ecf72abaf9e15d9d7064de46f01edf6e747dd097a62b8c
Contents?: true
Size: 1.39 KB
Versions: 7
Compression:
Stored size: 1.39 KB
Contents
# frozen_string_literal: true require "stepmod/utils/converters/synonym" require "stepmod/utils/term" require "glossarist" module Stepmod module Utils module Converters class Term < Stepmod::Utils::Converters::Base # We strip all the children in the case for "stem:[d]-manifold" # vs "stem:[d] -manifold" def treat_children(node, state) res = node.children.map { |child| treat(child, state) } res.map(&:strip).reject(&:empty?).join("") end def convert(node, state = {}) first_child = node.children.find do |child| child.name == "text" && !child.text.to_s.strip.empty? end unless first_child && node.text.split(";").length == 2 && defined?(Stepmod::Utils::Converters::Synonym) return Stepmod::Utils::Term.from_h( "definition" => treat_children(node, state).strip, ).to_mn_adoc end term_def, alt = node.text.split(";") alt_xml = Nokogiri::XML::Text.new(alt, Nokogiri::XML::Document.new) converted_alt = Stepmod::Utils::Converters::Synonym.new.convert(alt_xml) Stepmod::Utils::Term.from_h( "definition" => term_def, "synonyms" => [converted_alt], ).to_mn_adoc end end ReverseAdoc::Converters.register :term, Term.new end end end
Version data entries
7 entries across 7 versions & 1 rubygems