| Path: | README.rdoc |
| Last Update: | Wed Dec 21 14:20:25 +0200 2011 |
Project Contact: Akira FUNAI <funai.akira@gmail.com>
Ya2YAML is "yet another to_yaml". It emits YAML document with complete UTF8 support (string/binary detection, "\u" escape sequences and Unicode specific line breaks). I hope someone might find it useful until Syck/RbYAML come out with UTF8/16 support.
code:
# encoding: UTF-8
$KCODE = 'UTF8' unless RUBY_VERSION >= '1.9'
require 'ya2yaml'
obj = [
"abc\nxyz\n",
"日本語\n文字列\n",
"\xfd\xfe\xff",
]
puts obj.ya2yaml(:syck_compatible => true)
output:
---
- |
abc
xyz
- |
日本語
文字列
- !binary |
/f7/
When you require ‘ya2yaml’, public method ‘Object#ya2yaml’ is defined. Currently these Objects are supported.
as YAML generic types:
- Array - Hash - NilClass - String - TrueClass - FalseClass - Fixnum - Bignum - Float - Date - Time
as Ruby specific types:
- Symbol - Range - Regexp - Struct - everything else as a generic Object (serializes instance variables)
A String which contains any non-UTF8 character will be regarded as "binary" and encoded in BASE64.
# set them individually
obj.ya2yaml(
:indent_size => 4,
:hash_order => ['name','age','address'],
:minimum_block_length => 16,
:printable_with_syck => true,
:escape_b_specific => true,
:escape_as_utf8 => true
)
# or simply set this for a safe roundtrip with Syck.
obj.ya2yaml(:syck_compatible => true)
*CAUTION* Some of these options are to avoid compatibility issue with Syck. When you set these options to false, the emitted YAML document might not be loadable with YAML.load() although the syntax is valid.
Visit rubyforge.org/projects/ya2yaml
Ya2YAML is distributed with a MIT license, which can be found in the file LICENSE.