Class: Psychgus::SuperSniffer::Parent

Inherits:
Object
  • Object
show all
Defined in:
lib/psychgus/super_sniffer/parent.rb

Overview

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 Psychgus::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

See Also:

Author:

  • Jonathan Bradley Whited (@esotericpig)

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sniffer, node, debug_tag: nil, child_type: nil) ⇒ Parent

Initialize this class with parent data.

Parameters:

  • sniffer (SuperSniffer)

    the sniffer that contains this parent (not stored; used for data)

  • node (Psych::Nodes::Node)

    the node of this parent

  • debug_tag (:noface, Symbol, String) (defaults to: nil)

    the tag (class name, value) used for debugging and in #to_s

  • child_type (nil, :key, :value) (defaults to: nil)

    the next child's Mapping type, if node is a Mapping

Since:

  • 1.0.0


74
75
76
77
78
79
80
81
# File 'lib/psychgus/super_sniffer/parent.rb', line 74

def initialize(sniffer,node,debug_tag: nil,child_type: nil)
  @child_position = 1
  @child_type = child_type
  @debug_tag = debug_tag
  @level = sniffer.level
  @node = node
  @position = sniffer.position
end

Instance Attribute Details

#child_positionInteger

Calling the getter is fine; calling the setter is not and could cause weird results.

Returns:

  • (Integer)

    the next child's position

Since:

  • 1.0.0


54
55
56
# File 'lib/psychgus/super_sniffer/parent.rb', line 54

def child_position
  @child_position
end

#child_typenil, ...

Calling the getter is fine; calling the setter is not and could cause weird results.

Returns:

  • (nil, :key, :value)

    the next child's Mapping type, if #node is a Mapping

Since:

  • 1.0.0


59
60
61
# File 'lib/psychgus/super_sniffer/parent.rb', line 59

def child_type
  @child_type
end

#debug_tag:noface, ... (readonly)

Returns a tag (class name, value) for debugging; also used in #to_s.

Returns:

  • (:noface, Symbol, String)

    a tag (class name, value) for debugging; also used in #to_s

Since:

  • 1.0.0


62
63
64
# File 'lib/psychgus/super_sniffer/parent.rb', line 62

def debug_tag
  @debug_tag
end

#levelInteger (readonly)

Returns the level of this Node in the YAML.

Returns:

  • (Integer)

    the level of this Node in the YAML

Since:

  • 1.0.0


64
65
66
# File 'lib/psychgus/super_sniffer/parent.rb', line 64

def level
  @level
end

#nodePsych::Nodes::Node (readonly)

Returns the Node of this parent.

Returns:

  • (Psych::Nodes::Node)

    the Node of this parent

Since:

  • 1.0.0


65
66
67
# File 'lib/psychgus/super_sniffer/parent.rb', line 65

def node
  @node
end

#positionInteger (readonly)

Returns the position of this Node in the YAML.

Returns:

  • (Integer)

    the position of this Node in the YAML

Since:

  • 1.0.0


66
67
68
# File 'lib/psychgus/super_sniffer/parent.rb', line 66

def position
  @position
end

Instance Method Details

#anchorObject

See Also:

  • Psych::Nodes::Alias#anchor
  • Psych::Nodes::Mapping#anchor
  • Psych::Nodes::Scalar#anchor
  • Psych::Nodes::Sequence#anchor

Since:

  • 1.0.0


122
123
124
# File 'lib/psychgus/super_sniffer/parent.rb', line 122

def anchor()
  return node.anchor
end

#anchor=(anchor) ⇒ Object

See Also:

  • Psych::Nodes::Alias#anchor=
  • Psych::Nodes::Mapping#anchor=
  • Psych::Nodes::Scalar#anchor=
  • Psych::Nodes::Sequence#anchor=

Since:

  • 1.0.0


87
88
89
# File 'lib/psychgus/super_sniffer/parent.rb', line 87

def anchor=(anchor)
  node.anchor = anchor
end

#encodingObject

See Also:

  • Psych::Nodes::Stream#encoding

Since:

  • 1.0.0


127
128
129
# File 'lib/psychgus/super_sniffer/parent.rb', line 127

def encoding()
  return node.encoding
end

#end_columnObject

See Also:

  • Psych::Nodes::Node#end_column

Since:

  • 1.0.0


132
133
134
# File 'lib/psychgus/super_sniffer/parent.rb', line 132

def end_column()
  return node.end_column
end

#end_lineObject

See Also:

  • Psych::Nodes::Node#end_line

Since:

  • 1.0.0


137
138
139
# File 'lib/psychgus/super_sniffer/parent.rb', line 137

def end_line()
  return node.end_line
end

#implicit?Boolean Also known as: implicit

Returns:

  • (Boolean)

See Also:

  • Psych::Nodes::Document#implicit
  • Psych::Nodes::Mapping#implicit
  • Psych::Nodes::Sequence#implicit

Since:

  • 1.0.0


144
145
146
# File 'lib/psychgus/super_sniffer/parent.rb', line 144

def implicit?()
  return node.implicit
end

#implicit_end?Boolean Also known as: implicit_end

Returns:

  • (Boolean)

See Also:

  • Psych::Nodes::Document#implicit_end

Since:

  • 1.0.0


149
150
151
# File 'lib/psychgus/super_sniffer/parent.rb', line 149

def implicit_end?()
  return node.implicit_end
end

#node_of?(*names) ⇒ true, false

Check if this Node is of a certain type (Alias, Mapping, Scalar, Sequence, etc.).

New versions of Psych have alias?(), mapping?(), etc., so this is for old versions.

This is equivalent to the following (with less typing):

node.is_a?(Psych::Nodes::Alias)
node.is_a?(Psych::Nodes::Mapping)
node.is_a?(Psych::Nodes::Scalar)
node.is_a?(Psych::Nodes::Sequence)

Examples:

node.node_of?(:alias)
node.node_of?(:mapping)
node.node_of?(:scalar)
node.node_of?(:sequence)
node.node_of?(:alias,:mapping,:scalar,:sequence) # OR
node.node_of?(:doc,:map,:seq) # OR

Parameters:

  • names (Symbol, String)

    the type(s) to check using OR

Returns:

  • (true, false)

    true if this Node is one of the names type, else false

See Also:

Since:

  • 1.0.0


154
155
156
# File 'lib/psychgus/super_sniffer/parent.rb', line 154

def node_of?(*names)
  return node.node_of?(*names)
end

#plain=(plain) ⇒ Object

See Also:

  • Psych::Nodes::Scalar#plain=

Since:

  • 1.0.0


92
93
94
# File 'lib/psychgus/super_sniffer/parent.rb', line 92

def plain=(plain)
  node.plain = plain
end

#plain?Boolean Also known as: plain

Returns:

  • (Boolean)

See Also:

  • Psych::Nodes::Scalar#plain

Since:

  • 1.0.0


159
160
161
# File 'lib/psychgus/super_sniffer/parent.rb', line 159

def plain?()
  return node.plain
end

#quoted=(quoted) ⇒ Object

See Also:

  • Psych::Nodes::Scalar#quoted=

Since:

  • 1.0.0


97
98
99
# File 'lib/psychgus/super_sniffer/parent.rb', line 97

def quoted=(quoted)
  node.quoted = quoted
end

#quoted?Boolean Also known as: quoted

Returns:

  • (Boolean)

See Also:

  • Psych::Nodes::Scalar#quoted

Since:

  • 1.0.0


164
165
166
# File 'lib/psychgus/super_sniffer/parent.rb', line 164

def quoted?()
  return node.quoted
end

#start_columnObject

See Also:

  • Psych::Nodes::Node#start_column

Since:

  • 1.0.0


169
170
171
# File 'lib/psychgus/super_sniffer/parent.rb', line 169

def start_column()
  return node.start_column
end

#start_lineObject

See Also:

  • Psych::Nodes::Node#start_line

Since:

  • 1.0.0


174
175
176
# File 'lib/psychgus/super_sniffer/parent.rb', line 174

def start_line()
  return node.start_line
end

#styleObject

See Also:

  • Psych::Nodes::Mapping#style
  • Psych::Nodes::Scalar#style
  • Psych::Nodes::Sequence#style

Since:

  • 1.0.0


181
182
183
# File 'lib/psychgus/super_sniffer/parent.rb', line 181

def style()
  return node.style
end

#style=(style) ⇒ Object

See Also:

  • Psych::Nodes::Mapping#style=
  • Psych::Nodes::Scalar#style=
  • Psych::Nodes::Sequence#style=

Since:

  • 1.0.0


104
105
106
# File 'lib/psychgus/super_sniffer/parent.rb', line 104

def style=(style)
  node.style = style
end

#tagObject

See Also:

  • Psych::Nodes::Node#tag

Since:

  • 1.0.0


186
187
188
# File 'lib/psychgus/super_sniffer/parent.rb', line 186

def tag()
  return node.tag
end

#tag=(tag) ⇒ Object

See Also:

  • Psych::Nodes::Node#tag=

Since:

  • 1.0.0


109
110
111
# File 'lib/psychgus/super_sniffer/parent.rb', line 109

def tag=(tag)
  node.tag = tag
end

#tag_directivesObject

See Also:

  • Psych::Nodes::Document#tag_directives

Since:

  • 1.0.0


191
192
193
# File 'lib/psychgus/super_sniffer/parent.rb', line 191

def tag_directives()
  return node.tag_directives
end

#to_sString

Note:

If this method is modified, then tests will fail

Returns a String representation of this class for debugging and testing.

Returns:

  • (String)

    a String representation of this class for debugging and testing

Since:

  • 1.0.0


208
209
210
# File 'lib/psychgus/super_sniffer/parent.rb', line 208

def to_s()
  return "<#{@debug_tag}:(#{@level}:#{@position}):#{@child_type}:(:#{@child_position})>"
end

#valueObject

See Also:

  • Psych::Nodes::Scalar#value

Since:

  • 1.0.0


196
197
198
# File 'lib/psychgus/super_sniffer/parent.rb', line 196

def value()
  return node.value
end

#value=(value) ⇒ Object

See Also:

  • Psych::Nodes::Scalar#value=

Since:

  • 1.0.0


114
115
116
# File 'lib/psychgus/super_sniffer/parent.rb', line 114

def value=(value)
  node.value = value
end

#versionObject

See Also:

  • Psych::Nodes::Document#version

Since:

  • 1.0.0


201
202
203
# File 'lib/psychgus/super_sniffer/parent.rb', line 201

def version()
  return node.version
end