def to_yaml( opts = {} )
complex = false
if self.is_complex_yaml?
complex = true
elsif opts[:BestWidth].to_i > 0
if self.length > opts[:BestWidth] and opts[:UseFold]
complex = true
end
end
YAML::quick_emit( complex ? self.object_id : nil, opts ) { |out|
if complex
if not to_yaml_properties.empty?
out.map( self.to_yaml_type ) { |map|
map.add( 'str', "#{self}" )
to_yaml_properties.each { |m|
map.add( m, instance_variable_get( m ) )
}
}
elsif self.is_binary_data?
out.binary_base64( self )
elsif self =~ /^ |#{YAML::ESCAPE_CHAR}| $/
complex = false
else
out.node_text( self, to_yaml_fold )
end
end
if not complex
ostr = if out.options(:KeepValue)
self
elsif empty?
"''"
elsif self =~ /^[^#{YAML::WORD_CHAR}]| \#|#{YAML::ESCAPE_CHAR}|[#{YAML::SPACE_INDICATORS}]( |$)| $|\n|\'/
"\"#{YAML.escape( self )}\""
elsif YAML.detect_implicit( self ) != 'str'
"\"#{YAML.escape( self )}\""
else
self
end
out.simple( ostr )
end
}
end