Class: JsonDataExtractor::DirectNavigator
- Defined in:
- lib/json_data_extractor/direct_navigator.rb
Overview
Fast path navigator for simple JSONPath expressions Optimized to minimize recursive calls
Constant Summary collapse
- SIMPLE_PATH_PATTERN =
/^\$(\.[a-zA-Z_][\w]*|\[\d+\]|\[\*\])+$/
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path) ⇒ DirectNavigator
constructor
A new instance of DirectNavigator.
- #on(data) ⇒ Object
Constructor Details
#initialize(path) ⇒ DirectNavigator
Returns a new instance of DirectNavigator.
14 15 16 17 |
# File 'lib/json_data_extractor/direct_navigator.rb', line 14 def initialize(path) @path = path @segments = parse_segments(path) end |
Class Method Details
.simple_path?(path) ⇒ Boolean
10 11 12 |
# File 'lib/json_data_extractor/direct_navigator.rb', line 10 def self.simple_path?(path) path&.match?(SIMPLE_PATH_PATTERN) end |
Instance Method Details
#on(data) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/json_data_extractor/direct_navigator.rb', line 19 def on(data) # Use iterative approach instead of recursion to reduce method calls navigate(data) rescue StandardError => e # Fallback to empty array if navigation fails [] end |