Class: DocxManipulator::Content

Inherits:
Object
  • Object
show all
Defined in:
lib/docx_manipulator/content.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, new_content, options = {}) ⇒ Content

Returns a new instance of Content.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/docx_manipulator/content.rb', line 7

def initialize(path, new_content, options = {})
  @writes_to_file = path
  @new_content = if new_content.kind_of?(File)
                   new_content.read
                 else
                   new_content
                 end
  if options.include?(:xslt)
    xslt = Nokogiri::XSLT.parse(options[:xslt])
    data = Nokogiri::XML.parse(@new_content)
    @new_content = xslt.transform(data).to_s
  end
end

Instance Attribute Details

#writes_to_fileObject (readonly)

Returns the value of attribute writes_to_file.



5
6
7
# File 'lib/docx_manipulator/content.rb', line 5

def writes_to_file
  @writes_to_file
end

Instance Method Details

#process(output) ⇒ Object



21
22
23
24
# File 'lib/docx_manipulator/content.rb', line 21

def process(output)
  output.put_next_entry @writes_to_file
  output.write @new_content
end