Class: Writexlsx::Package::XMLWriterSimple

Inherits:
Object
  • Object
show all
Defined in:
lib/write_xlsx/package/xml_writer_simple.rb

Constant Summary collapse

XMLNS =
'http://schemas.openxmlformats.org/spreadsheetml/2006/main'

Instance Method Summary collapse

Constructor Details

#initializeXMLWriterSimple


12
13
14
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 12

def initialize
  @io = StringIO.new
end

Instance Method Details

#characters(data) ⇒ Object


85
86
87
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 85

def characters(data)
  io_write(escape_data(data))
end

#closeObject


93
94
95
96
97
98
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 93

def close
  if @filename
    File.open(@filename, "wb") { |f| f << string }
  end
  @io.close
end

#crlfObject


89
90
91
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 89

def crlf
  io_write("\n")
end

#data_element(tag, data, attr = []) ⇒ Object


67
68
69
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 67

def data_element(tag, data, attr = [])
  tag_elements(tag, attr) { io_write("#{escape_data(data)}") }
end

#empty_tag(tag, attr = []) ⇒ Object


54
55
56
57
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 54

def empty_tag(tag, attr = [])
  str = "<#{tag}#{key_vals(attr)}/>"
  io_write(str)
end

#empty_tag_encoded(tag, attr = []) ⇒ Object


59
60
61
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 59

def empty_tag_encoded(tag, attr = [])
  io_write(empty_tag_encoded_str(tag, attr))
end

#empty_tag_encoded_str(tag, attr = []) ⇒ Object


63
64
65
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 63

def empty_tag_encoded_str(tag, attr = [])
  "<#{tag}#{key_vals(attr)}/>"
end

#end_tag(tag) ⇒ Object


46
47
48
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 46

def end_tag(tag)
  io_write(end_tag_str(tag))
end

#end_tag_str(tag) ⇒ Object


50
51
52
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 50

def end_tag_str(tag)
  "</#{tag}>"
end

#io_write(str) ⇒ Object


104
105
106
107
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 104

def io_write(str)
  @io << str
  str
end

#set_xml_writer(filename = nil) ⇒ Object


16
17
18
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 16

def set_xml_writer(filename = nil)
  @filename = filename
end

#si_element(data, attr) ⇒ Object

Optimised tag writer ? for shared strings <si> elements.


74
75
76
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 74

def si_element(data, attr)
  tag_elements('si') { data_element('t', data, attr) }
end

#si_rich_element(data) ⇒ Object

Optimised tag writer for shared strings <si> rich string elements.


81
82
83
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 81

def si_rich_element(data)
  io_write("<si>#{data}</si>")
end

#start_tag(tag, attr = []) ⇒ Object


38
39
40
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 38

def start_tag(tag, attr = [])
  io_write(start_tag_str(tag, attr))
end

#start_tag_str(tag, attr = []) ⇒ Object


42
43
44
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 42

def start_tag_str(tag, attr = [])
  "<#{tag}#{key_vals(attr)}>"
end

#stringObject


100
101
102
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 100

def string
  @io.string
end

#tag_elements(tag, attributes = []) ⇒ Object


25
26
27
28
29
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 25

def tag_elements(tag, attributes = [])
  start_tag(tag, attributes)
  yield
  end_tag(tag)
end

#tag_elements_str(tag, attributes = []) ⇒ Object


31
32
33
34
35
36
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 31

def tag_elements_str(tag, attributes = [])
  str = ''
  str << start_tag_str(tag, attributes)
  str << yield
  str << end_tag_str(tag)
end

#xml_decl(encoding = 'UTF-8', standalone = true) ⇒ Object


20
21
22
23
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 20

def xml_decl(encoding = 'UTF-8', standalone = true)
  str = %Q!<?xml version="1.0" encoding="#{encoding}" standalone="#{standalone ? 'yes' : 'no'}"?>\n!
  io_write(str)
end