Class: Docx::Document
- Inherits:
-
Object
- Object
- Docx::Document
- Defined in:
- lib/docx/document.rb
Class Method Summary collapse
Instance Method Summary collapse
- #each_paragraph ⇒ Object
-
#initialize(path, &block) ⇒ Document
constructor
A new instance of Document.
- #save(path) ⇒ Object
- #to_s ⇒ Object (also: #text)
-
#update ⇒ Object
TODO: Flesh this out to be compatible with other files TODO: Method to set flag on files that have been edited, probably by inserting something at the end of methods that make edits?.
Constructor Details
Class Method Details
.open(path, &block) ⇒ Object
17 18 19 |
# File 'lib/docx/document.rb', line 17 def self.open(path, &block) self.new(path, &block) end |
Instance Method Details
#each_paragraph ⇒ Object
21 22 23 |
# File 'lib/docx/document.rb', line 21 def each_paragraph paragraphs.each { |p| yield(p) } end |
#save(path) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/docx/document.rb', line 36 def save(path) update Zip::ZipOutputStream.open(path) do |out| zip.each do |entry| out.put_next_entry(entry.name) if @replace[entry.name] out.write(@replace[entry.name]) else out.write(zip.read(entry.name)) end end end zip.close end |
#to_s ⇒ Object Also known as: text
25 26 27 |
# File 'lib/docx/document.rb', line 25 def to_s paragraphs.map(&:to_s).join("\n") end |
#update ⇒ Object
TODO: Flesh this out to be compatible with other files TODO: Method to set flag on files that have been edited, probably by inserting something at the end of methods that make edits?
32 33 34 |
# File 'lib/docx/document.rb', line 32 def update @replace["word/document.xml"] = doc.serialize :save_with => 0 end |