Class: Writexlsx::Package::XMLWriterSimple
- Inherits:
-
Object
- Object
- Writexlsx::Package::XMLWriterSimple
- Defined in:
- lib/write_xlsx/package/xml_writer_simple.rb
Instance Method Summary collapse
- #characters(data) ⇒ Object
- #close ⇒ Object
- #crlf ⇒ Object
- #data_element(tag, data, attr = []) ⇒ Object
- #empty_tag(tag, attr = []) ⇒ Object
- #end_tag(tag) ⇒ Object
-
#initialize ⇒ XMLWriterSimple
constructor
A new instance of XMLWriterSimple.
- #io_write(str) ⇒ Object
- #set_xml_writer(filename = nil) ⇒ Object
- #start_tag(tag, attr = []) ⇒ Object
- #string ⇒ Object
- #tag_elements(tag, attributes = []) ⇒ Object
- #xml_decl(encoding = 'UTF-8', standalone = true) ⇒ Object
Constructor Details
#initialize ⇒ XMLWriterSimple
Returns a new instance of XMLWriterSimple.
10 11 12 |
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 10 def initialize @io = StringIO.new end |
Instance Method Details
#characters(data) ⇒ Object
50 51 52 |
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 50 def characters(data) escape_xml_chars(data) end |
#close ⇒ Object
58 59 60 |
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 58 def close @io.close end |
#crlf ⇒ Object
54 55 56 |
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 54 def crlf io_write("\n") end |
#data_element(tag, data, attr = []) ⇒ Object
46 47 48 |
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 46 def data_element(tag, data, attr = []) tag_elements(tag, attr) { io_write("#{characters(data)}") } end |
#empty_tag(tag, attr = []) ⇒ Object
41 42 43 44 |
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 41 def empty_tag(tag, attr = []) str = "<#{tag}#{key_vals(attr)} />" io_write(str) end |
#end_tag(tag) ⇒ Object
36 37 38 39 |
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 36 def end_tag(tag) str = "</#{tag}>" io_write(str) end |
#io_write(str) ⇒ Object
66 67 68 69 |
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 66 def io_write(str) @io << str str end |
#set_xml_writer(filename = nil) ⇒ Object
14 15 16 17 18 |
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 14 def set_xml_writer(filename = nil) fh = File.open(filename, "wb") @io = fh end |
#start_tag(tag, attr = []) ⇒ Object
31 32 33 34 |
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 31 def start_tag(tag, attr = []) str = "<#{tag}#{key_vals(attr)}>" io_write(str) end |
#string ⇒ Object
62 63 64 |
# File 'lib/write_xlsx/package/xml_writer_simple.rb', line 62 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 |
#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 |