Class: ODDB::Util::Multilingual

Inherits:
Object
  • Object
show all
Includes:
OddbUri, M10lMethods
Defined in:
lib/oddb/export/yaml.rb,
lib/oddb/util/multilingual.rb,
lib/oddb/persistence/og/util/multilingual.rb

Constant Summary

Constants included from OddbUri

OddbUri::YAML_URI

Instance Attribute Summary

Attributes included from M10lMethods

#canonical, #synonyms

Instance Method Summary collapse

Methods included from M10lMethods

#<=>, #==, #empty?, #method_missing, #to_s

Methods included from OddbUri

#to_yaml, #to_yaml_map, #to_yaml_type

Constructor Details

#initialize(canonical = {}) ⇒ Multilingual

Returns a new instance of Multilingual.



51
52
53
54
# File 'lib/oddb/util/multilingual.rb', line 51

def initialize(canonical={})
  super
  @synonyms = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ODDB::Util::M10lMethods

Instance Method Details

#add_synonym(synonym) ⇒ Object



55
56
57
# File 'lib/oddb/util/multilingual.rb', line 55

def add_synonym(synonym)
  @synonyms.push(synonym).uniq! && synonym
end

#allObject



58
59
60
61
62
# File 'lib/oddb/util/multilingual.rb', line 58

def all
  terms = super.concat(@synonyms)
  terms.concat(terms.collect do |term| term.gsub(/[^\w]/, '') end)
  terms.uniq
end

#merge(other) ⇒ Object



63
64
65
# File 'lib/oddb/util/multilingual.rb', line 63

def merge(other)
  @synonyms.concat(other.all).uniq!
end