Belodon.Input (belodon v0.3.0)
View SourceModule responsible for handling input retrieval and caching
This module provides facilities to obtain input data for a given year and day by:
- Building a local storage path: A file path is generated where the input will be cached.
- Checking for cached input: If the file exists locally, its contents are returned.
- Fetching remote input: If not cached, input is fetched from an external source, its body is processed, and then written locally.
Workflow overview
graph TD
A["Generate local file path based on year/day"] --> B["If file exists?"]
B -- "No" --> C["Build external input path for fetching"]
B -- "Yes" --> F
C --> D["Fetch input data"]
D --> E["Process & cache input locally"]
E --> F["Process local file & return content"]
Summary
Functions
Retrieves the input data for a given year and day.
Writes the given content to the file at the specified path.
Functions
Retrieves the input data for a given year and day.
This function is the primary entry point for obtaining problem input. It works as follows:
- Local Path Generation: Computes the local file path.
- Cache Check: If the file does not exist, it will:
- Build an external path.
- Fetch the input
- Trim and cache the fetched content locally using
write_file!/2.
- Return Value: Reads and returns the contents of the local file.
Parameters
year: A binary representing the year (e.g.,"2023").day: A binary representing the day (e.g.,"15").opts: A keyword list impacting the way data is stored in the file. See Options.
Options
:trim: Set tofalseif data should not be trimmed (Default:true)
Returns
- A binary containing the input data.
Writes the given content to the file at the specified path.
Before writing, it ensures that the target directory exists by creating it if necessary.
Parameters
content: The content to be written.path: The complete file path where the content should be stored.
Returns
:okupon successful file write.