Class: Libera::Tei
- Inherits:
-
Object
- Object
- Libera::Tei
- Includes:
- OM::XML::Document
- Defined in:
- lib/libera/tei.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_anon_block(text) ⇒ Object
- #add_body ⇒ Object
- #add_page_break(page_img) ⇒ Object
- #add_text ⇒ Object
Class Method Details
.xml_template ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/libera/tei.rb', line 35 def self.xml_template builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml| xml.TEI("xmlns"=>"http://www.tei-c.org/ns/1.0") { xml.teiHeader{ xml.fileDesc{ xml.titleStmt{ xml.title } xml.publicationStmt{ xml.p_ } xml.sourceDesc{ xml.p_ } } } xml.text_{ xml.body{ xml.ab } } } end return builder.doc end |
Instance Method Details
#add_anon_block(text) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/libera/tei.rb', line 106 def add_anon_block(text) if self.find_by_terms(:text, :body, :page_break).blank? # Raise error, page break required raise "Page Break not found, unable to add anon block" end if self.find_by_terms(:text, :body, :page_break).count == 1 self.template_registry.add_next_sibling(self.find_by_terms(:text, :body, :page_break => 0).first, :anon_block, text) else self.template_registry.add_next_sibling(self.find_by_terms(:text, :body, :page_break).last, :anon_block, text) end end |
#add_body ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/libera/tei.rb', line 70 def add_body begin self.template_registry.add_child(self.find_by_terms(:text => 0), :body) rescue NoMethodError raise "Unable to add XML node to base template" end end |
#add_page_break(page_img) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/libera/tei.rb', line 78 def add_page_break(page_img) # any text? if self.find_by_terms(:text => 0).blank? self.add_text end # any body? if self.find_by_terms(:text, :body => 0).blank? self.add_body end # any anon breaks? ab_count = self.find_by_terms(:text, :body, :anon_block).count if ab_count == 1 && self.find_by_terms(:text, :body, :anon_block).first.text.blank? self.find_by_terms(:text, :body, :anon_block).first.remove ab_count = 0 end if !(ab_count > 0) # if not add to child of body self.template_registry.add_child(self.find_by_terms(:text, :body => 0), :page_break, page_img) else # else add as sibling self.template_registry.add_next_sibling(self.find_by_terms(:text, :body, :anon_block).last, :page_break, page_img) end end |
#add_text ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/libera/tei.rb', line 62 def add_text begin self.template_registry.add_child(self.ng_xml.root, :text) rescue NoMethodError raise "Unable to add XML node to base template" end end |