Class: EPUB::Publication::Package::Manifest::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/epub/maker/publication.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contentObject

Returns the value of attribute content.



256
257
258
# File 'lib/epub/maker/publication.rb', line 256

def content
  @content
end

#content_fileObject

Returns the value of attribute content_file.



256
257
258
# File 'lib/epub/maker/publication.rb', line 256

def content_file
  @content_file
end

Instance Method Details

#editObject

Save document into EPUB archive when block ended



277
278
279
280
# File 'lib/epub/maker/publication.rb', line 277

def edit
  yield if block_given?
  save
end

#edit_with_nokogiri {|Nokgiri::XML::Document| ... } ⇒ Object

Save document into EPUB archive at end of block

Yields:

  • (Nokgiri::XML::Document)


294
295
296
297
298
299
# File 'lib/epub/maker/publication.rb', line 294

def edit_with_nokogiri
  doc = Nokogiri.XML(read)
  yield doc if block_given?
  self.content = doc.to_xml
  save
end

#edit_with_rexml {|REXML::Document| ... } ⇒ Object

Save document into EPUB archive at end of block

Yields:

  • (REXML::Document)


284
285
286
287
288
289
290
# File 'lib/epub/maker/publication.rb', line 284

def edit_with_rexml
  require 'rexml/document'
  doc = REXML::Document.new(read)
  yield doc if block_given?
  self.content = doc.to_s
  save
end

#save(archive = nil) ⇒ Object

Parameters:

  • archive (Zip::Archive|nil) (defaults to: nil)

    archive to save content. If nil, open archive in this method

Raises:

  • StandardError when no content nor content_file



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/epub/maker/publication.rb', line 260

def save(archive=nil)
  if archive
    if content
      archive.add_or_replace_buffer entry_name, content
    elsif content_file
      archive.add_or_replace_file entry_name, content_file
    else
      raise 'no content nor content_file'
    end
  else
    Zip::Archive.open manifest.package.book.epub_file do |archive|
      save archive
    end
  end
end