lib/stepmod/utils/term.rb in stepmod-utils-0.3.23 vs lib/stepmod/utils/term.rb in stepmod-utils-0.3.24
- old
+ new
@@ -5,28 +5,41 @@
class Term < Glossarist::LocalizedConcept
# Term acronym
attr_accessor :acronym
def to_mn_adoc
- mn_adoc = ["=== #{definition}"]
+ mn_adoc = ["=== #{definition.map(&:content).join}"]
mn_adoc << "\nalt:[#{acronym}]" if acronym
- mn_adoc << "\n\n#{designations.join(", ")}" if designations&.any?
+ mn_adoc << "\n\n#{designations.map(&:designation).join(", ")}" if designations&.any?
mn_adoc.join
end
class << self
def from_h(hash)
_, definition, acronym = treat_acronym(hash["definition"])
- hash["definition"] = definition
+ hash["definition"] = [definition]
+
hash["acronym"] = acronym.gsub(/\(|\)/, "") if acronym
- hash["designations"] = hash["synonyms"]
+ add_designations(hash, hash["synonyms"]) if hash["synonyms"]
- super(hash.reject { |k, _| k == "synonyms" })
+ new(hash.reject { |k, _| k == "synonyms" })
end
private
+
+ def add_designations(hash, synonyms)
+ hash["designations"] ||= []
+ hash["designations"] << designation_hash(synonyms) if synonyms
+ end
+
+ def designation_hash(value, type = "expression")
+ {
+ "designation" => value,
+ "type" => type,
+ }
+ end
def treat_acronym(term_def)
return [nil, term_def.strip, nil] unless term_def.match?(/.+\(.+?\)$/)
term_def.match(/(.+?)(\(.+\))$/).to_a