Class: Tc211::Termbase::Concept
- Inherits:
-
Hash
- Object
- Hash
- Tc211::Termbase::Concept
- Defined in:
- lib/tc211/termbase/concept.rb
Constant Summary collapse
- DEFAULT_LANGUAGE =
"eng".freeze
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
Instance Method Summary collapse
- #add_term(term) ⇒ Object
- #default_term ⇒ Object
-
#initialize(options = {}) ⇒ Concept
constructor
A new instance of Concept.
- #terms ⇒ Object
- #to_file(filename) ⇒ Object
- #to_glossarist_concept ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Concept
Returns a new instance of Concept.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/tc211/termbase/concept.rb', line 7 def initialize( = {}) super terms = .delete(:terms) || [] terms.each do |term| add_term(term) end .each_pair do |k, v| send("#{k}=", v) end end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/tc211/termbase/concept.rb', line 3 def id @id end |
Instance Method Details
#add_term(term) ⇒ Object
26 27 28 |
# File 'lib/tc211/termbase/concept.rb', line 26 def add_term(term) self[term.language_code] = term end |
#default_term ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/tc211/termbase/concept.rb', line 34 def default_term if self[DEFAULT_LANGUAGE] self[DEFAULT_LANGUAGE] else puts "[tc211-termbase] term (lang: #{keys.first}, ID: #{id}) is \ missing a corresponding English term, probably needs updating." self[keys.first] end end |
#terms ⇒ Object
30 31 32 |
# File 'lib/tc211/termbase/concept.rb', line 30 def terms values end |
#to_file(filename) ⇒ Object
55 56 57 58 59 |
# File 'lib/tc211/termbase/concept.rb', line 55 def to_file(filename) File.open(filename, "w") do |file| file.write(to_hash.to_yaml) end end |
#to_glossarist_concept ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/tc211/termbase/concept.rb', line 61 def to_glossarist_concept concept = Tc211::Termbase::Glossarist::ManagedConcept.new( data: { id: id.to_s }, ) localized_concepts = [] terms.map do |term| next if term.nil? localized_concepts << term.to_localized_concept_hash end concept.localized_concepts = localized_concepts concept end |
#to_hash ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/tc211/termbase/concept.rb', line 44 def to_hash default_hash = { "term" => default_term.term, "termid" => id, } inject(default_hash) do |acc, (lang, term)| acc.merge!(lang => term.to_hash) end end |