Class: OllamaAgent::Skills::JsonExtractor::BalancedScan
- Inherits:
-
Object
- Object
- OllamaAgent::Skills::JsonExtractor::BalancedScan
- Defined in:
- lib/ollama_agent/skills/json_extractor.rb
Overview
Walks the buffer once tracking bracket depth while ignoring brackets nested inside JSON string literals. Returns the slice length that closes the initial opener, or nil when the input is unbalanced.
Instance Method Summary collapse
-
#initialize(buffer) ⇒ BalancedScan
constructor
A new instance of BalancedScan.
- #length ⇒ Object
Constructor Details
#initialize(buffer) ⇒ BalancedScan
Returns a new instance of BalancedScan.
45 46 47 48 49 50 51 52 |
# File 'lib/ollama_agent/skills/json_extractor.rb', line 45 def initialize(buffer) @buffer = buffer @opener = buffer[0] @closer = CLOSERS.fetch(@opener) @depth = 0 @in_string = false @escape = false end |
Instance Method Details
#length ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/ollama_agent/skills/json_extractor.rb', line 54 def length @buffer.each_char.with_index do |char, idx| consume(char) return idx + 1 if !@in_string && @depth.zero? && idx.positive? end nil end |