lib/yaml-write-stream/stateful.rb in yaml-write-stream-1.0.4 vs lib/yaml-write-stream/stateful.rb in yaml-write-stream-2.0.0

- old
+ new

@@ -113,26 +113,41 @@ def current stack.last end def write_scalar(value, quote = false) - style = if value == '' + case value + when Numeric + write_numeric_scalar(value) + when NilClass + write_nil_scalar + else + write_string_scalar(value.to_s, quote) + end + end + + def write_string_scalar(value, quote = false) + style = if quote Psych::Nodes::Scalar::DOUBLE_QUOTED else - if !quote || !value - Psych::Nodes::Scalar::ANY - else - Psych::Nodes::Scalar::DOUBLE_QUOTED - end + Psych::Nodes::Scalar::PLAIN end - quoted = value == '' - value = value ? value : '' + # value, anchor, tag, plain, quoted, style + emitter.scalar( + value, nil, nil, true, true, style + ) + end + def write_numeric_scalar(value) # value, anchor, tag, plain, quoted, style emitter.scalar( - value, nil, nil, true, quoted, style + value.to_s, nil, nil, true, false, Psych::Nodes::Scalar::PLAIN ) + end + + def write_nil_scalar + write_string_scalar('') end end class StatefulMappingWriter < StatefulWriter def after_initialize