Class: Ya2YAML

Inherits:
Object show all
Includes:
Constants
Defined in:
lib/ya2yaml.rb

Overview

Author

Akira FUNAI

Copyright

Copyright © 2006-2010 Akira FUNAI

License

MIT License

Defined Under Namespace

Modules: Constants

Constant Summary

Constants included from Constants

Constants::ESCAPE_SEQ, Constants::ESCAPE_SEQ_LB, Constants::ESCAPE_SEQ_NS, Constants::ESCAPE_SEQ_WS, Constants::REX_ANY_LB, Constants::REX_BOOL, Constants::REX_CR, Constants::REX_CRLF, Constants::REX_FLOAT, Constants::REX_INT, Constants::REX_LF, Constants::REX_LS, Constants::REX_MERGE, Constants::REX_NEL, Constants::REX_NORMAL_LB, Constants::REX_NULL, Constants::REX_PS, Constants::REX_TIMESTAMP, Constants::REX_VALUE, Constants::UCS_0X2028, Constants::UCS_0X2029, Constants::UCS_0X85, Constants::UCS_0XA0

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Ya2YAML

Returns a new instance of Ya2YAML.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ya2yaml.rb', line 9

def initialize(opts = {})
  options = opts.dup
  options[:indent_size] = 2          if options[:indent_size].to_i <= 0
  options[:minimum_block_length] = 0 if options[:minimum_block_length].to_i <= 0
  options.update(
    {
      :printable_with_syck  => true,
      :escape_b_specific    => true,
      :escape_as_utf8       => true,
    }
  ) if options[:syck_compatible]

  @options = options
end

Instance Method Details

#_ya2yaml(obj) ⇒ Object



24
25
26
27
28
29
# File 'lib/ya2yaml.rb', line 24

def _ya2yaml(obj)
  raise 'set $KCODE to "UTF8".' if (RUBY_VERSION < '1.9.0') && ($KCODE != 'UTF8')
  '--- ' + emit(obj, 1) + "\n"
rescue SystemStackError
  raise ArgumentError, "ya2yaml can't handle circular references"
end