Class: ODDB::Export::Yaml::Infos

Inherits:
Object
  • Object
show all
Defined in:
lib/oddb/export/yaml.rb

Direct Known Subclasses

Fachinfos, Patinfos

Instance Method Summary collapse

Instance Method Details

#export(io) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/oddb/export/yaml.rb', line 153

def export(io)
  raise "please specify which type of document you want to export" unless infotype
  infos = []
  ## Documents may be garbage-collected during this export. That's why we'll
  #  keep names in a separate table on the stack, and assign them just before
  #  calling #to_yaml
  names = {}
  ODDB::Drugs::Sequence.all do |seq|
    info = seq.send infotype
    # export sequence names as title
    unless info.empty?
      lnms = names[info.oid] ||= {}
      info.canonical.each do |key, doc|
        if (doc = info.send(key)) && (name = identify_name(seq, key))
          lnms[key] = name
        end
      end
      infos.push info
    end
  end
  infos.uniq!
  infos.each do |info|
    info.canonical.each do |key, doc|
      doc.title = names[info.oid][key]
    end
    io.puts info.to_yaml
  end
  nil
end