Class: DataSpork::XmlWriter

Inherits:
BaseWriter show all
Defined in:
lib/data_spork/xml_writer.rb

Instance Attribute Summary

Attributes inherited from BaseWriter

#owner, #started

Instance Method Summary collapse

Methods inherited from BaseWriter

#initialize, #start, #started?

Constructor Details

This class inherits a constructor from DataSpork::BaseWriter

Instance Method Details

#begin_put_rowObject



28
29
30
# File 'lib/data_spork/xml_writer.rb', line 28

def begin_put_row
  print "#{indent}#{begin_row}"
end

#begin_rowObject

Answer the tag defining a row.



59
60
61
# File 'lib/data_spork/xml_writer.rb', line 59

def begin_row
  begin_tag(row_tag)
end

#begin_tag(h = nil) ⇒ Object

Answer a begin tag using the current header, or else override it with the sender’s tag.



49
50
51
# File 'lib/data_spork/xml_writer.rb', line 49

def begin_tag(h = nil)
  "<#{h || header}>"
end

#build_schema_tagObject

Output the schema with the root tag.



15
16
17
# File 'lib/data_spork/xml_writer.rb', line 15

def build_schema_tag
  %Q(#{root_tag} #{schema_uri} effective_date="#{effective_date}")
end

#end_put_rowObject



32
33
34
# File 'lib/data_spork/xml_writer.rb', line 32

def end_put_row
  print "#{indent}#{end_row}"
end

#end_rowObject

Answer the closing tag for the current row.



64
65
66
# File 'lib/data_spork/xml_writer.rb', line 64

def end_row
  end_tag(row_tag)
end

#end_tag(h = nil) ⇒ Object

Answer the end tag using the current header, or else override it with the sender’s tag.



54
55
56
# File 'lib/data_spork/xml_writer.rb', line 54

def end_tag(h = nil)
  "</#{h || header}>"
end

#finishObject

Close out the XML document.



24
25
26
# File 'lib/data_spork/xml_writer.rb', line 24

def finish
  print end_tag root_tag if started?
end

#indent(level = 1) ⇒ Object

Answer a string prefix for the specified indent level.

Parameters:

  • :level

    specifies the indent level; default is 1.



70
71
72
# File 'lib/data_spork/xml_writer.rb', line 70

def indent(level = 1)
  "\t" * level
end

#put_columnObject

Output the current column enclosing it with XML tags.



44
45
46
# File 'lib/data_spork/xml_writer.rb', line 44

def put_column
  print "#{indent 2}#{begin_tag}#{col_value}#{end_tag}"
end

#put_tag(tag, value) ⇒ Object

Output the value enclosing it with the specified XML tag.

Parameters:

  • :tag

    the xml tag name

  • :value

    the value to output



39
40
41
# File 'lib/data_spork/xml_writer.rb', line 39

def put_tag(tag, value)
  print "#{indent 2}#{begin_tag tag}#{value || ''}#{end_tag tag}"
end

#schema_uriObject



19
20
21
# File 'lib/data_spork/xml_writer.rb', line 19

def schema_uri
  %q(xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance")
end

#start_documentObject

Output the XML document preface.



4
5
6
7
# File 'lib/data_spork/xml_writer.rb', line 4

def start_document
  print '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>'
  start_schema
end

#start_schemaObject

Output the schema with the root tag.



10
11
12
# File 'lib/data_spork/xml_writer.rb', line 10

def start_schema
  print begin_tag(build_schema_tag)
end