Class: ODDB::Text::Document

Inherits:
Model
  • Object
show all
Defined in:
lib/oddb/text/document.rb,
lib/oddb/export/yaml.rb,
lib/oddb/persistence/odba/text/document.rb

Overview

to migrate Document to be a subclass of Model:

Drugs::Sequence.all { |seq| need = false; [:fachinfo, :patinfo].each { |key| if(ml = seq.instance_variable_get("@#{key}")); need = true; seq.instance_variable_set("@#{key}", nil); if(doc = ml.de); info = seq.send(key); if(prev = doc.instance_variable_get('@previous_sources')); info.previous_sources[:de] = prev; doc.instance_eval { remove_instance_variable('@previous_sources') }; end; if((source = doc.source) && (saved = Text::Document.find_by_source(source))); doc = saved; end; info.de = doc; info.save; info.de.save; end; end }; seq.save if need }

Constant Summary

Constants included from OddbUri

OddbUri::YAML_URI

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#initializeDocument

Returns a new instance of Document.



13
14
15
# File 'lib/oddb/text/document.rb', line 13

def initialize
  @chapters = []
end

Instance Attribute Details

#chaptersObject (readonly)

Returns the value of attribute chapters.



12
13
14
# File 'lib/oddb/text/document.rb', line 12

def chapters
  @chapters
end

#dateObject

Returns the value of attribute date.



11
12
13
# File 'lib/oddb/text/document.rb', line 11

def date
  @date
end

#sourceObject

Returns the value of attribute source.



11
12
13
# File 'lib/oddb/text/document.rb', line 11

def source
  @source
end

#titleObject

Returns the value of attribute title.



11
12
13
# File 'lib/oddb/text/document.rb', line 11

def title
  @title
end

Instance Method Details

#add_chapter(chapter) ⇒ Object



16
17
18
# File 'lib/oddb/text/document.rb', line 16

def add_chapter(chapter)
  @chapters.push chapter
end

#chapter(idx_or_name) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/oddb/text/document.rb', line 19

def chapter(idx_or_name)
  case idx_or_name
  when Integer
    @chapters[idx_or_name]
  else
    @chapters.find { |ch| ch.name == idx_or_name }
  end
end

#chapter_namesObject



27
28
29
30
31
32
33
# File 'lib/oddb/text/document.rb', line 27

def chapter_names
  @chapters.select { |chapter| 
    chapter.paragraphs.size > 1 
  }.collect { |chapter| 
    chapter.name 
  }
end

#remove_chapter(chapter) ⇒ Object



34
35
36
# File 'lib/oddb/text/document.rb', line 34

def remove_chapter(chapter)
  @chapters.delete(chapter)
end

#to_sObject



37
38
39
# File 'lib/oddb/text/document.rb', line 37

def to_s
  @chapters.join("\n")
end