class Psychgus::SuperSniffer::Parent
A container for the parent of a Psych::Nodes::Node.
A parent is a Mapping, Sequence, or a Key (Scalar) of a Mapping.
You can use the getters in this class in {Styler} to filter what to change.
If a Node method has not been exposed, you can use {#node}:
if parent.node_of?(:scalar) parent.value = 'FUBAR' parent.node.value = 'FUBAR' # Same as above parent.fubar = true # NoMethodError parent.node.fubar = true # Use some new Psych::Nodes::Node method not in this version # of Psychgus or that is not exposed by Parent end
@author Jonathan Bradley Whited @since 1.0.0
@see SuperSniffer
@see SuperSniffer#start_parent
SuperSniffer#start_parent
@see SuperSniffer#end_parent
SuperSniffer#end_parent
@see Styler
Attributes
Calling the getter is fine; calling the setter is not and could cause weird results.
@return [Integer] the next child's position
Calling the getter is fine; calling the setter is not and could cause weird results.
@return [nil,:key,:value] the next child's Mapping type, if {#node} is a Mapping
@return [:noface,Symbol,String] a tag (class name, value) for debugging; also used in {#to_s}
Public Class Methods
Initialize this class with parent data.
@param sniffer [SuperSniffer] the sniffer that contains this parent (not stored; used for data) @param node [Psych::Nodes::Node] the node of this parent @param debug_tag
[:noface,Symbol,String] the tag (class name, value) used for debugging and in {#to_s} @param child_type
[nil,:key,:value] the next child's Mapping type, if node
is a Mapping
# File lib/psychgus/super_sniffer/parent.rb, line 66 def initialize(sniffer,node,debug_tag: nil,child_type: nil) super(node) @child_position = 1 @child_type = child_type @debug_tag = debug_tag @level = sniffer.level @node = node @position = sniffer.position end
Public Instance Methods
@api private
# File lib/psychgus/super_sniffer/parent.rb, line 78 def __getobj__ return @node end
Check if the children of this parent are keys to a Mapping.
@return [true,false] whether the children are keys to a Mapping
@since 1.2.0
# File lib/psychgus/super_sniffer/parent.rb, line 87 def child_key? return @child_type == :key end
Check if the children of this parent are values to a Mapping (i.e., values to a key).
@return [true,false] whether the children are values to a Mapping (i.e., values to a key)
@since 1.2.0
# File lib/psychgus/super_sniffer/parent.rb, line 96 def child_value? return @child_type == :value end
@see Psych::Nodes::Document#implicit @see Psych::Nodes::Mapping#implicit @see Psych::Nodes::Sequence#implicit
# File lib/psychgus/super_sniffer/parent.rb, line 103 def implicit? return @node.implicit end
@see Psych::Nodes::Document#implicit_end
# File lib/psychgus/super_sniffer/parent.rb, line 108 def implicit_end? return @node.implicit_end end
(see Ext::NodeExt#node_of?
)
# File lib/psychgus/super_sniffer/parent.rb, line 113 def node_of?(*names) return @node.node_of?(*names) end
@see Psych::Nodes::Scalar#plain
# File lib/psychgus/super_sniffer/parent.rb, line 118 def plain? return @node.plain end
@see Psych::Nodes::Scalar#quoted
# File lib/psychgus/super_sniffer/parent.rb, line 123 def quoted? return @node.quoted end
@note If this method is modified, then tests will fail
@return [String] a String representation of this class for debugging and testing
# File lib/psychgus/super_sniffer/parent.rb, line 130 def to_s return "<#{@debug_tag}:(#{@level}:#{@position}):#{@child_type}:(:#{@child_position})>" end