lib/tc211/termbase/concept_collection.rb in tc211-termbase-0.2.1 vs lib/tc211/termbase/concept_collection.rb in tc211-termbase-0.2.3

- old
+ new

@@ -1,32 +1,40 @@ require_relative "concept" module Tc211::Termbase + class ConceptCollection < Hash + def add_term(term) + if self[term.id] + self[term.id].add_term(term) + else + self[term.id] = Concept.new( + id: term.id, + terms: [term], + ) + end + end -class ConceptCollection < Hash - - def add_term(term) - if self[term.id] - self[term.id].add_term(term) - else - self[term.id] = Concept.new( - id: term.id, - terms: [term] - ) + def to_hash + inject({}) do |acc, (id, concept)| + acc.merge!(id => concept.to_hash) + end end - end - def to_hash - self.inject({}) do |acc, (id, concept)| - acc.merge!(id => concept.to_hash) + def to_file(filename) + File.open(filename, "w") do |file| + file.write(to_hash.to_yaml) + end end - end - def to_file(filename) - File.open(filename,"w") do |file| - file.write(to_hash.to_yaml) + def to_concept_collection + collection = Glossarist::ManagedConceptCollection.new + + values.each do |term_concept| + next if term_concept.nil? + + collection.store(term_concept.to_glossarist_concept) + end + + collection end end - end - -end \ No newline at end of file