Class: RubyXL::Writer::GenericWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyXL/writer/generic_writer.rb

Instance Method Summary collapse

Constructor Details

#initialize(workbook) ⇒ GenericWriter

Returns a new instance of GenericWriter.



8
9
10
11
12
# File 'lib/rubyXL/writer/generic_writer.rb', line 8

def initialize(workbook)
  @workbook = workbook
  # +self.class+ makes sure constant is pulled from descendant class, not from this one.
  # self.class::FILEPATH
end

Instance Method Details

#add_to_zip(zipfile) ⇒ Object



27
28
29
30
31
# File 'lib/rubyXL/writer/generic_writer.rb', line 27

def add_to_zip(zipfile)
  output = write
  return if output.nil?
  zipfile.get_output_stream(filepath) { |f| f << output }
end

#filepathObject



14
15
16
# File 'lib/rubyXL/writer/generic_writer.rb', line 14

def filepath
  raise 'Subclass responsebility'
end

#ooxml_objectObject



33
34
35
# File 'lib/rubyXL/writer/generic_writer.rb', line 33

def ooxml_object
  raise 'Subclass responsebility'
end

#render_xml {|seed_xml| ... } ⇒ Object

Yields:

  • (seed_xml)


18
19
20
21
22
23
24
25
# File 'lib/rubyXL/writer/generic_writer.rb', line 18

def render_xml
  seed_xml = Nokogiri::XML('<?xml version = "1.0" standalone ="yes"?>')
  seed_xml.encoding = 'UTF-8'

  yield(seed_xml)

  seed_xml.to_xml({ :indent => 0, :save_with => Nokogiri::XML::Node::SaveOptions::AS_XML })
end

#writeObject



37
38
39
# File 'lib/rubyXL/writer/generic_writer.rb', line 37

def write
  ooxml_object && ooxml_object.write_xml
end