Class: String

Inherits:
Object show all
Defined in:
lib/syck/rubytypes.rb

Instance Method Summary collapse

Instance Method Details

#is_binary_data?Boolean

Returns:

  • (Boolean)


152
153
154
# File 'lib/syck/rubytypes.rb', line 152

def is_binary_data?
    self.count("\x00-\x7F", "^ -~\t\r\n").fdiv(self.size) > 0.3 || self.index("\x00") unless self.empty?
end

#is_complex_yaml?Boolean

Returns:

  • (Boolean)


149
150
151
# File 'lib/syck/rubytypes.rb', line 149

def is_complex_yaml?
    to_yaml_style or not to_yaml_properties.empty? or self =~ /\n.+/
end

#to_yaml(opts = {}) ⇒ Object



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/syck/rubytypes.rb', line 170

def to_yaml( opts = {} )
       return super unless YAML == Syck
	Syck::quick_emit( is_complex_yaml? ? self : nil, opts ) do |out|
           if is_binary_data?
               out.scalar( "tag:yaml.org,2002:binary", [self].pack("m"), :literal )
           elsif to_yaml_properties.empty?
               out.scalar( taguri, self, self =~ /^:/ ? :quote2 : to_yaml_style )
           else
               out.map( taguri, to_yaml_style ) do |map|
                   map.add( 'str', "#{self}" )
                   to_yaml_properties.each do |m|
                       map.add( m, instance_variable_get( m ) )
                   end
               end
           end
       end
end