Class: Tc211::Termbase::ConceptCollection
- Inherits:
-
Hash
- Object
- Hash
- Tc211::Termbase::ConceptCollection
- Defined in:
- lib/tc211/termbase/concept_collection.rb
Instance Method Summary collapse
- #add_term(term) ⇒ Object
- #to_concept_collection ⇒ Object
- #to_file(filename) ⇒ Object
- #to_hash ⇒ Object
Instance Method Details
#add_term(term) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/tc211/termbase/concept_collection.rb', line 5 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 |
#to_concept_collection ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/tc211/termbase/concept_collection.rb', line 28 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 |
#to_file(filename) ⇒ Object
22 23 24 25 26 |
# File 'lib/tc211/termbase/concept_collection.rb', line 22 def to_file(filename) File.open(filename, "w") do |file| file.write(to_hash.to_yaml) end end |
#to_hash ⇒ Object
16 17 18 19 20 |
# File 'lib/tc211/termbase/concept_collection.rb', line 16 def to_hash inject({}) do |acc, (id, concept)| acc.merge!(id => concept.to_hash) end end |