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.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 61 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.
41 42 43 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 41 def child_position @child_position end |
#child_type ⇒ nil, ...
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_type @child_type end |
#debug_tag ⇒ :noface, ... (readonly)
Returns a tag (class name, value) for debugging; also used in #to_s.
49 50 51 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 49 def debug_tag @debug_tag end |
#level ⇒ Integer (readonly)
Returns the level of this Node in the YAML.
51 52 53 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 51 def level @level end |
#node ⇒ Psych::Nodes::Node (readonly)
Returns the Node of this parent.
52 53 54 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 52 def node @node end |
#position ⇒ Integer (readonly)
Returns the position of this Node in the YAML.
53 54 55 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 53 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.
73 74 75 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 73 def __getobj__ return @node end |
#child_key? ⇒ true, false
Check if the children of this parent are keys to a Mapping.
80 81 82 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 80 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).
87 88 89 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 87 def child_value? return @child_type == :value end |
#implicit? ⇒ Boolean
94 95 96 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 94 def implicit? return @node.implicit end |
#implicit_end? ⇒ Boolean
99 100 101 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 99 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)
104 105 106 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 104 def node_of?(*names) return @node.node_of?(*names) end |
#plain? ⇒ Boolean
109 110 111 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 109 def plain? return @node.plain end |
#quoted? ⇒ Boolean
114 115 116 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 114 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.
121 122 123 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 121 def to_s return "<#{@debug_tag}:(#{@level}:#{@position}):#{@child_type}:(:#{@child_position})>" end |