Class: Docxtor::Package::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/docxtor/package/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parts, document) ⇒ Builder

Returns a new instance of Builder.



6
7
8
9
# File 'lib/docxtor/package/builder.rb', line 6

def initialize(parts, document)
  @parts = parts
  @parts['document'] = Part.new("word/document.xml", document.content)
end

Instance Attribute Details

#partsObject (readonly)

Returns the value of attribute parts.



4
5
6
# File 'lib/docxtor/package/builder.rb', line 4

def parts
  @parts
end

Instance Method Details

#save(filepath) ⇒ Object



11
12
13
14
15
# File 'lib/docxtor/package/builder.rb', line 11

def save(filepath)
  Zip::ZipOutputStream.open(filepath) do |ostream|
    write_parts(ostream)
  end
end

#to_streamObject



17
18
19
20
21
22
23
# File 'lib/docxtor/package/builder.rb', line 17

def to_stream
  ostream = Zip::ZipOutputStream.new("streamed", true)
  write_parts(ostream)
  string_io = ostream.close_buffer
  string_io.rewind
  string_io
end