Class: Osgeo::Termbase::Concept
- Inherits:
-
Hash
- Object
- Hash
- Osgeo::Termbase::Concept
- Defined in:
- lib/osgeo/termbase/concept.rb
Constant Summary collapse
- DEFAULT_LANGUAGE =
"eng"
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#terms ⇒ Object
Returns the value of attribute terms.
Instance Method Summary collapse
- #add_term(term) ⇒ Object
- #default_term ⇒ Object
-
#initialize(options = {}) ⇒ Concept
constructor
A new instance of Concept.
- #to_file(filename) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Concept
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/osgeo/termbase/concept.rb', line 10 def initialize(={}) terms = .delete(:terms) || [] terms.each do |term| add_term(term) end .each_pair do |k,v| self.send("#{k}=", v) end end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/osgeo/termbase/concept.rb', line 6 def id @id end |
#terms ⇒ Object
Returns the value of attribute terms.
7 8 9 |
# File 'lib/osgeo/termbase/concept.rb', line 7 def terms @terms end |
Instance Method Details
#add_term(term) ⇒ Object
27 28 29 |
# File 'lib/osgeo/termbase/concept.rb', line 27 def add_term(term) self[term.language_code] = term end |
#default_term ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/osgeo/termbase/concept.rb', line 31 def default_term if self[DEFAULT_LANGUAGE] self[DEFAULT_LANGUAGE] else puts "[osgeo-termbase] term (lang: #{keys.first}, ID: #{id}) is missing a corresponding English term, probably needs updating." self[keys.first] end end |
#to_file(filename) ⇒ Object
51 52 53 54 55 |
# File 'lib/osgeo/termbase/concept.rb', line 51 def to_file(filename) File.open(filename,"w") do |file| file.write(to_hash.to_yaml) end end |
#to_hash ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/osgeo/termbase/concept.rb', line 40 def to_hash default_hash = { "term" => default_term.term, "termid" => id } self.inject(default_hash) do |acc, (lang, term)| acc.merge!(lang => term.to_hash) end end |