MIL-003: Step 2 - New flash cards
Review record RC-025 (Go, autonomous mode, not independent). Task: MIL-003#1 Task: MIL-003#2 Task: MIL-003#3 Task: MIL-003#4 Task: MIL-003#5
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
"""CSV implementation of the vocabulary port.
|
||||
|
||||
@file csv_vocabulary_repository.py
|
||||
@brief The CsvVocabularyRepository adapter.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from flash_card.domain.entities.vocabulary import Vocabulary
|
||||
from flash_card.domain.errors.vocabulary_errors import VocabularyFormatError
|
||||
from flash_card.infrastructure.persistence.csv_word_list import read_word_list
|
||||
|
||||
|
||||
class CsvVocabularyRepository:
|
||||
"""Loads the delivered word list from a CSV file."""
|
||||
|
||||
def __init__(self, path: Path) -> None:
|
||||
"""Create the repository.
|
||||
|
||||
@param path The word list file.
|
||||
"""
|
||||
## @brief The word list file.
|
||||
self._path = path
|
||||
|
||||
def load(self) -> Vocabulary:
|
||||
"""Load the word list.
|
||||
|
||||
@return The vocabulary.
|
||||
@throws VocabularyNotFoundError When the file does not exist.
|
||||
@throws VocabularyFormatError When the file is malformed or has no card.
|
||||
"""
|
||||
pair, cards = read_word_list(self._path)
|
||||
if not cards:
|
||||
raise VocabularyFormatError(f"{self._path}: word list has no card")
|
||||
return Vocabulary(pair, cards)
|
||||
Reference in New Issue
Block a user