Class: Psychgus::SuperSniffer::Parent
- Inherits:
-
Delegator
- Object
- Delegator
- 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.
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_position ⇒ Integer
Calling the getter is fine; calling the setter is not and could cause weird results.
54 55 56 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 54 def child_position @child_position end |
#child_type ⇒ nil, ...
Calling the getter is fine; calling the setter is not and could cause weird results.
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.
62 63 64 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 62 def debug_tag @debug_tag end |
#level ⇒ Integer (readonly)
Returns the level of this Node in the YAML.
64 65 66 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 64 def level @level end |
#node ⇒ Psych::Nodes::Node (readonly)
Returns the Node of this parent.
65 66 67 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 65 def node @node end |
#position ⇒ Integer (readonly)
Returns the position of this Node in the YAML.
66 67 68 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 66 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.
84 85 86 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 84 def __getobj__ return @node end |
#child_key? ⇒ true, false
Check if the children of this parent are keys to a Mapping.
93 94 95 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 93 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).
102 103 104 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 102 def child_value?() return @child_type == :value end |
#implicit? ⇒ Boolean
109 110 111 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 109 def implicit?() return @node.implicit end |
#implicit_end? ⇒ Boolean
114 115 116 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 114 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)
119 120 121 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 119 def node_of?(*names) return @node.node_of?(*names) end |
#plain? ⇒ Boolean
124 125 126 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 124 def plain?() return @node.plain end |
#quoted? ⇒ Boolean
129 130 131 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 129 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.
136 137 138 |
# File 'lib/psychgus/super_sniffer/parent.rb', line 136 def to_s() return "<#{@debug_tag}:(#{@level}:#{@position}):#{@child_type}:(:#{@child_position})>" end |