Class: ODDB::Util::M10lDocument

Inherits:
Model
  • Object
show all
Includes:
M10lMethods
Defined in:
lib/oddb/model.rb,
lib/oddb/util/m10l_document.rb,
lib/oddb/persistence/odba/util/m10l_document.rb

Constant Summary

Constants included from OddbUri

OddbUri::YAML_URI

Instance Attribute Summary collapse

Attributes included from M10lMethods

#canonical, #synonyms

Instance Method Summary collapse

Methods included from M10lMethods

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

Methods inherited from Model

#__odba_delete__, #__odba_save__, _serializables, belongs_to, connections, connector, connectors, #data_origin, #data_origins, delegates, #delete, find_by_uid, has_many, is_coded, m10l_document, multilingual, #odba_serializables, #oid, on_delete, on_save, predicates, #save, #saved?, serializables, serialize, singular

Methods included from ODBA::Persistable

#to_yaml_properties

Methods included from Yaml

append_features, #to_yaml_properties

Methods included from OddbUri

#to_yaml, #to_yaml_map, #to_yaml_type

Constructor Details

#initialize(canonical = {}) ⇒ M10lDocument

Returns a new instance of M10lDocument.



13
14
15
16
# File 'lib/oddb/util/m10l_document.rb', line 13

def initialize(canonical={})
  super
  @previous_sources = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/oddb/util/m10l_document.rb', line 24

def method_missing(meth, *args, &block)
  case meth.to_s
  when /^([a-z]{2})=$/
    lang = $~[1].to_sym
    if(previous = @canonical[lang])
      add_previous_source(lang, previous.source)
    end
    @canonical.store(lang, args.first)
  else
    super(meth, *args, &block)
  end
end

Instance Attribute Details

#previous_sourcesObject (readonly)

Returns the value of attribute previous_sources.



12
13
14
# File 'lib/oddb/util/m10l_document.rb', line 12

def previous_sources
  @previous_sources
end

Instance Method Details

#add_previous_source(lang, source) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/oddb/util/m10l_document.rb', line 17

def add_previous_source(lang, source)
  sources = (@previous_sources[lang.to_sym] ||= [])
  sources.push source
  sources.compact!
  sources.uniq!
  sources
end