Class: Psychgus::SuperSniffer::Parent
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Psychgus::SuperSniffer::Parent
- 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. = true # NoMethodError
parent.node. = true # Use some new Psych::Nodes::Node method not in this version
# of Psychgus or that is not exposed by Parent
end
Instance Attribute Summary collapse
-
#child_position ⇒ Integer
Calling the getter is fine; calling the setter is not and could cause weird results.
-
#child_type ⇒ nil, ...
Calling the getter is fine; calling the setter is not and could cause weird results.
-
#debug_tag ⇒ :noface, ...
readonly
A tag (class name, value) for debugging; also used in #to_s.
-
#level ⇒ Integer
readonly
The level of this Node in the YAML.
-
#node ⇒ Psych::Nodes::Node
readonly
The Node of this parent.
-
#position ⇒ Integer
readonly
The position of this Node in the YAML.
Instance Method Summary collapse
- #__getobj__ ⇒ Object private
-
#child_key? ⇒ true, false
Check if the children of this parent are keys to a Mapping.
-
#child_value? ⇒ true, false
Check if the children of this parent are values to a Mapping (i.e., values to a key).
- #implicit? ⇒ Boolean
- #implicit_end? ⇒ Boolean
-
#initialize(sniffer, node, debug_tag: nil, child_type: nil) ⇒ Parent
constructor
Initialize this class with parent data.
-
#node_of?(*names) ⇒ true, false
Check if this Node is of a certain type (Alias, Mapping, Scalar, Sequence, etc.).
- #plain? ⇒ Boolean
- #quoted? ⇒ Boolean
-
#to_s ⇒ String
A String representation of this class for debugging and testing.
Constructor Details
#initialize(sniffer, node, debug_tag: nil, child_type: nil) ⇒ Parent
Initialize this class with parent data.
66 67 68 69 70 71 72 73 74 75 |
# 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 |
Instance Attribute Details
#child_position ⇒ Integer
Calling the getter is fine; calling the setter is not and could cause weird results.
46 47 48 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 46 def child_position @child_position end |
#child_type ⇒ nil, ...
Calling the getter is fine; calling the setter is not and could cause weird results.
51 52 53 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 51 def child_type @child_type end |
#debug_tag ⇒ :noface, ... (readonly)
Returns a tag (class name, value) for debugging; also used in #to_s.
54 55 56 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 54 def debug_tag @debug_tag end |
#level ⇒ Integer (readonly)
Returns the level of this Node in the YAML.
56 57 58 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 56 def level @level end |
#node ⇒ Psych::Nodes::Node (readonly)
Returns the Node of this parent.
57 58 59 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 57 def node @node end |
#position ⇒ Integer (readonly)
Returns the position of this Node in the YAML.
58 59 60 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 58 def position @position end |
Instance Method Details
#__getobj__ ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
78 79 80 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 78 def __getobj__ return @node end |
#child_key? ⇒ true, false
Check if the children of this parent are keys to a Mapping.
87 88 89 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 87 def child_key? return @child_type == :key end |
#child_value? ⇒ true, false
Check if the children of this parent are values to a Mapping (i.e., values to a key).
96 97 98 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 96 def child_value? return @child_type == :value end |
#implicit? ⇒ Boolean
103 104 105 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 103 def implicit? return @node.implicit end |
#implicit_end? ⇒ Boolean
108 109 110 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 108 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)
113 114 115 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 113 def node_of?(*names) return @node.node_of?(*names) end |
#plain? ⇒ Boolean
118 119 120 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 118 def plain? return @node.plain end |
#quoted? ⇒ Boolean
123 124 125 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 123 def quoted? return @node.quoted end |
#to_s ⇒ String
If this method is modified, then tests will fail
Returns a String representation of this class for debugging and testing.
130 131 132 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 130 def to_s return "<#{@debug_tag}:(#{@level}:#{@position}):#{@child_type}:(:#{@child_position})>" end |