Skip to content

Commit

Permalink
refactor: Refactor ScriptContentReader
Browse files Browse the repository at this point in the history
  • Loading branch information
kvankova committed Nov 3, 2024
1 parent 7ad0199 commit feb4da1
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/script_content_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ def _extract_part(self, script: ScriptMetadata) -> str:
# Try extracting as object first, then fall back to section
is_object, start, end = self._find_object_bounds(script)
if is_object:
return self._convert_lines_to_content(lines, start, end)
return "\n".join(lines[start:end])

# Extract section if not an object
start, end = self._find_section_bounds(lines)
if not self._validate_section_bounds(start, end, script):
return ""

return self._convert_lines_to_content(lines, start, end)
return "\n".join(lines[start:end])

def _validate_section_bounds(
self, start: int | None, end: int | None, script: ScriptMetadata
Expand All @@ -100,25 +100,14 @@ def _validate_section_bounds(

return True

def _convert_lines_to_content(
self, lines: list[str], start: int | None, end: int | None
) -> str:
if start is None or end is None:
return ""
return "\n".join(lines[start:end])

def _find_section_bounds(self, lines: list[str]) -> tuple[int | None, int | None]:
start = None
end = None

for i, line in enumerate(lines):
if re.search(self._section_start_regex, line):
start = i + 1
elif re.search(self._section_end_regex, line):
end = i
break
return start, i

return start, end
return None, None

def _find_object_bounds(
self, script: ScriptMetadata
Expand Down

0 comments on commit feb4da1

Please sign in to comment.