Class: Psych::Merge::MappingEntry
- Inherits:
-
Object
- Object
- Psych::Merge::MappingEntry
- Defined in:
- lib/psych/merge/file_analysis.rb
Overview
Represents a key-value entry in a YAML mapping
Instance Attribute Summary collapse
-
#comment_tracker ⇒ CommentTracker
readonly
Comment tracker.
-
#key ⇒ NodeWrapper
readonly
The key node.
-
#lines ⇒ Array<String>
readonly
Source lines.
-
#value ⇒ NodeWrapper
readonly
The value node.
Instance Method Summary collapse
-
#anchor ⇒ String?
Get the anchor if present.
-
#content ⇒ String
Get the content for this entry.
-
#end_line ⇒ Integer?
Get the end line (from the value).
-
#freeze_node? ⇒ Boolean
Check if this is a freeze node.
-
#initialize(key:, value:, lines:, comment_tracker:) ⇒ MappingEntry
constructor
A new instance of MappingEntry.
-
#inspect ⇒ String
String representation.
-
#key_name ⇒ String?
Get the key name as a string.
-
#line_range ⇒ Range?
Get the line range.
-
#location ⇒ Object
Location-like object for compatibility.
-
#mapping? ⇒ Boolean
Check if this is a mapping.
-
#scalar? ⇒ Boolean
Check if this is a scalar.
-
#sequence? ⇒ Boolean
Check if this is a sequence.
-
#signature ⇒ Array
Generate signature for this entry.
-
#start_line ⇒ Integer?
Get the start line (from the key).
Constructor Details
#initialize(key:, value:, lines:, comment_tracker:) ⇒ MappingEntry
Returns a new instance of MappingEntry.
266 267 268 269 270 271 |
# File 'lib/psych/merge/file_analysis.rb', line 266 def initialize(key:, value:, lines:, comment_tracker:) @key = key @value = value @lines = lines @comment_tracker = comment_tracker end |
Instance Attribute Details
#comment_tracker ⇒ CommentTracker (readonly)
Returns Comment tracker.
260 261 262 |
# File 'lib/psych/merge/file_analysis.rb', line 260 def comment_tracker @comment_tracker end |
#key ⇒ NodeWrapper (readonly)
Returns The key node.
251 252 253 |
# File 'lib/psych/merge/file_analysis.rb', line 251 def key @key end |
#lines ⇒ Array<String> (readonly)
Returns Source lines.
257 258 259 |
# File 'lib/psych/merge/file_analysis.rb', line 257 def lines @lines end |
#value ⇒ NodeWrapper (readonly)
Returns The value node.
254 255 256 |
# File 'lib/psych/merge/file_analysis.rb', line 254 def value @value end |
Instance Method Details
#anchor ⇒ String?
Get the anchor if present
350 351 352 |
# File 'lib/psych/merge/file_analysis.rb', line 350 def anchor @value.anchor end |
#content ⇒ String
Get the content for this entry
307 308 309 310 311 |
# File 'lib/psych/merge/file_analysis.rb', line 307 def content return "" unless start_line && end_line (start_line..end_line).map { |ln| @lines[ln - 1] }.compact.join("\n") end |
#end_line ⇒ Integer?
Get the end line (from the value)
293 294 295 |
# File 'lib/psych/merge/file_analysis.rb', line 293 def end_line @value.end_line || @key.end_line end |
#freeze_node? ⇒ Boolean
Check if this is a freeze node
326 327 328 |
# File 'lib/psych/merge/file_analysis.rb', line 326 def freeze_node? false end |
#inspect ⇒ String
String representation
356 357 358 |
# File 'lib/psych/merge/file_analysis.rb', line 356 def inspect "#<#{self.class.name} key=#{key_name.inspect} lines=#{start_line}..#{end_line}>" end |
#key_name ⇒ String?
Get the key name as a string
275 276 277 |
# File 'lib/psych/merge/file_analysis.rb', line 275 def key_name @key.value end |
#line_range ⇒ Range?
Get the line range
299 300 301 302 303 |
# File 'lib/psych/merge/file_analysis.rb', line 299 def line_range return unless start_line && end_line start_line..end_line end |
#location ⇒ Object
Location-like object for compatibility
320 321 322 |
# File 'lib/psych/merge/file_analysis.rb', line 320 def location @location ||= FreezeNode::Location.new(start_line, end_line) end |
#mapping? ⇒ Boolean
Check if this is a mapping
332 333 334 |
# File 'lib/psych/merge/file_analysis.rb', line 332 def mapping? @value.mapping? end |
#scalar? ⇒ Boolean
Check if this is a scalar
344 345 346 |
# File 'lib/psych/merge/file_analysis.rb', line 344 def scalar? @value.scalar? end |
#sequence? ⇒ Boolean
Check if this is a sequence
338 339 340 |
# File 'lib/psych/merge/file_analysis.rb', line 338 def sequence? @value.sequence? end |
#signature ⇒ Array
Generate signature for this entry
315 316 317 |
# File 'lib/psych/merge/file_analysis.rb', line 315 def signature [:mapping_entry, key_name] end |
#start_line ⇒ Integer?
Get the start line (from the key)
281 282 283 284 285 286 287 288 289 |
# File 'lib/psych/merge/file_analysis.rb', line 281 def start_line # Include leading comments in start line leading = @comment_tracker.leading_comments_before(@key.start_line || 1) if leading.any? leading.first[:line] else @key.start_line end end |