Ejemplo n.º 1
0
        public static Node ToYamlNode(MutableString /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep)
        {
            if (RubyOps.IsTrue(_IsBinaryData.Target(_IsBinaryData, rep.Context, self)))
            {
                return(rep.BaseCreateNode(self.ConvertToBytes()));
            }

            string    str   = self.ConvertToString();
            RubyArray props = RubyRepresenter.ToYamlProperties(rep.Context, self);

            if (props.Count == 0)
            {
                MutableString taguri = RubyRepresenter.TagUri(rep.Context, self);

                char style = (char)0;
                if (str.StartsWith(":"))
                {
                    style = '"';
                }
                else
                {
                    MutableString styleStr = RubyRepresenter.ToYamlStyle(rep.Context, self) as MutableString;
                    if (styleStr != null && styleStr.Length > 0)
                    {
                        style = styleStr.GetChar(0);
                    }
                }

                return(rep.Scalar(taguri != null ? taguri.ConvertToString() : "", str, style));
            }

            Hash map = new Hash(rep.Context);

            map.Add(MutableString.Create("str"), str);
            RubyRepresenter.AddYamlProperties(rep.Context, self, map, props);
            return(rep.Map(self, map));
        }