Class: RawXML

Inherits:
String show all
Defined in:
lib/xml_serialization.rb

Overview

create a string class that doesn’t get escaped when dumped into XML stream

Constant Summary

Constants inherited from String

String::XML_HEAD_PATTERN

Instance Method Summary collapse

Methods inherited from String

#strip_xml_head, #strip_xml_head!

Constructor Details

#initialize(string, options = {}) ⇒ RawXML

Returns a new instance of RawXML.



52
53
54
55
# File 'lib/xml_serialization.rb', line 52

def initialize(string, options={})
  @options = options
  super string
end

Instance Method Details

#to_xml(options_arg = {}) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/xml_serialization.rb', line 57

def to_xml(options_arg={})
  options = @options.merge options_arg
  builder = options[:builder] || 
            Builder::XmlMarkup.new(:indent => options[:indent])

  add_tag = options.has_key?(:no_tag) ? !options[:no_tag] : options[:root]
  return builder.no_tag!(self.strip_xml_head) unless add_tag 

  tag = options[:root] || self.class.name.downcase
  dasherize = ! options.has_key?(:dasherize) || options[:dasherize]
  tag = dasherize ? tag.to_s.dasherize : tag

  builder.raw_tag!(tag, self.strip_xml_head)
end