Class: String
Class Method Summary collapse
Instance Method Summary collapse
- #__is_str ⇒ Object
- #is_binary_data? ⇒ Boolean
- #is_complex_yaml? ⇒ Boolean
- #to_yaml_node(repre) ⇒ Object
Class Method Details
.yaml_new(klass, tag, val) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/rbyaml/rubytypes.rb', line 149 def String.yaml_new( klass, tag, val ) val = val.unpack("m")[0] if tag == "tag:yaml.org,2002:binary" val = { 'str' => val } if String === val if Hash === val s = klass.allocate # Thank you, NaHi String.instance_method(:initialize). bind(s). call( val.delete( 'str' ) ) val.each { |k,v| s.instance_variable_set( k, v ) } s else raise RbYAML::TypeError, "Invalid String: " + val.inspect end end |
Instance Method Details
#__is_str ⇒ Object
9 |
# File 'lib/rbyaml/util.rb', line 9 def __is_str; true end |
#is_binary_data? ⇒ Boolean
146 147 148 |
# File 'lib/rbyaml/rubytypes.rb', line 146 def is_binary_data? ( self.count( "^ -~", "^\r\n" ) / self.size > 0.3 || self.count( "\x00" ) > 0 ) unless empty? end |
#is_complex_yaml? ⇒ Boolean
143 144 145 |
# File 'lib/rbyaml/rubytypes.rb', line 143 def is_complex_yaml? to_yaml_style or not to_yaml_properties.empty? or self =~ /\n.+/ end |
#to_yaml_node(repre) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/rbyaml/rubytypes.rb', line 164 def to_yaml_node(repre) RbYAML::quick_emit_node( is_complex_yaml? ? object_id : nil, repre ) do |rep| if is_binary_data? rep.scalar( "tag:yaml.org,2002:binary", [self].pack("m"), "|") elsif to_yaml_properties.empty? rep.scalar(taguri, self, self =~ /^:/ ? '"' : to_yaml_style ) else mep = {} mep['str'] = "#{self}" to_yaml_properties.each do |m| mep.put[m] = instance_variable_get( m ) end rep.map( taguri, mep, to_yaml_style ) end end end |