module Psych::Comments::NodeUtils
Public Instance Methods
Source
# File lib/psych/comments/emitter.rb, line 53 def has_anchor(node) case node when Psych::Nodes::Scalar, Psych::Nodes::Mapping, Psych::Nodes::Sequence !!node.anchor else false end end
Source
# File lib/psych/comments/emitter.rb, line 49 def has_bullet(node) node.is_a?(Psych::Nodes::Sequence) && !node.children.empty? end
Source
# File lib/psych/comments/emitter.rb, line 38 def single_line(node) case node when Psych::Nodes::Scalar, Psych::Nodes::Alias node.leading_comments.empty? && node.trailing_comments.empty? when Psych::Nodes::Mapping, Psych::Nodes::Sequence node.children.empty? else false end end
Source
# File lib/psych/comments/emitter.rb, line 19 def stringify_adjust_scalar(node, indent_str = 0) node2 = Psych::Nodes::Scalar.new(node.value, nil, nil, node.plain, node.quoted, node.style) if node.tag if node.style == Psych::Nodes::Scalar::PLAIN node2.plain = true else node2.quoted = true end end s = stringify_node(node2).sub(/\n\z/, "") if node.style == Psych::Nodes::Scalar::DOUBLE_QUOTED || node.style == Psych::Nodes::Scalar::SINGLE_QUOTED || node.style == Psych::Nodes::Scalar::PLAIN s = s.gsub(/\s*\n\s*/, " ") else s = s.gsub(/\n/, "\n#{indent_str}") end s.gsub(/\n\s+$/, "\n") end
Source
# File lib/psych/comments/emitter.rb, line 4 def stringify_node(node) case node when Psych::Nodes::Stream node.to_yaml when Psych::Nodes::Document strm = Psych::Nodes::Stream.new strm.children << node stringify_node(strm) else doc = Psych::Nodes::Document.new([], [], true) doc.children << node stringify_node(doc) end end