Class: PowerPointPptx::Document
- Inherits:
-
Object
- Object
- PowerPointPptx::Document
- Defined in:
- lib/power_point_pptx/document.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(file) ⇒ Document
constructor
A new instance of Document.
- #save ⇒ Object
- #slides ⇒ Object
- #stream ⇒ Object
Constructor Details
#initialize(file) ⇒ Document
Returns a new instance of Document.
14 15 16 |
# File 'lib/power_point_pptx/document.rb', line 14 def initialize(file) @files = Zip::File.open_buffer(file) end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
12 13 14 |
# File 'lib/power_point_pptx/document.rb', line 12 def files @files end |
Class Method Details
.open(file) ⇒ Object
8 9 10 |
# File 'lib/power_point_pptx/document.rb', line 8 def self.open(file) new(file) end |
Instance Method Details
#save ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/power_point_pptx/document.rb', line 46 def save new_zip_file_path = Tempfile.new("new_pptx").path Zip::OutputStream.open(new_zip_file_path) do |new_zip_file| @files.each do |entry| = @slides.find { || .entry_name == entry.name } new_zip_file.put_next_entry(entry.name) if .nil? new_zip_file.write(entry.get_input_stream.read) else new_zip_file.write(.xml) end end end File.new(new_zip_file_path) end |
#slides ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/power_point_pptx/document.rb', line 18 def @slides = [] @files .select { |entry| entry.name.include?("ppt/slides/slide") } .map do |entry| @slides << Slide.new(entry, entry.name) end @slides end |
#stream ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/power_point_pptx/document.rb', line 29 def stream stream = Zip::OutputStream.write_buffer do |out| @files.each do |entry| = @slides.find { || .entry_name == entry.name } out.put_next_entry(entry.name) if .nil? out.write(entry.get_input_stream.read) else out.write(.xml) end end end stream.rewind stream end |