Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/ys1/parent_and_child.rb
Overview
OpenClass String
Instance Method Summary collapse
-
#to_pacs(start_line) ⇒ Array<YS1::ParentAndChild>
Converts the string into an array of YS1::ParentAndChild objects.
Instance Method Details
#to_pacs(start_line) ⇒ Array<YS1::ParentAndChild>
Note:
For very large data, consider splitting the file using the csplit command before processing to avoid loading the entire file into memory at once.
Converts the string into an array of YS1::ParentAndChild objects.
Each line that matches the start_line pattern becomes a new parent object. Subsequent lines are added as children to the most recent parent object.
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ys1/parent_and_child.rb', line 72 def to_pacs(start_line) each_line.with_object([]) do |raw_line, pacs| line = raw_line.chomp if line.match?(start_line) pacs << YS1::ParentAndChild.new(line) else pacs.last&.add_child(line) end end end |