igneus / calendarium-romanum

liturgical calendar library (Roman Catholic, post-Vatican II)
50 stars 21 forks source link

Implement SanctoraleWriter #62

Closed mkasberg closed 3 years ago

mkasberg commented 3 years ago

SanctoraleLoader is a class that already exists to read a txt file into a Sanctorale instance. It would be nice to also have a SanctoraleWriter class to do this operation in reverse, writing Sanctorale data to a txt file in the same format.

The SanctoraleWriter is probably less complicated than the loader because we don't need to do any regex or other pattern matching. We simply iterate the celebrations in the Sanctorale and write a line for each.

There was some room for judgement here because the file format allows for a couple different variations of the way months or ranks could be serialized. I opted to serialize using the preferences that universal-en.txt was already using, which also seemed to make the file the most readable. (E.g. We serialize month headings rather than writing the month on every line). An added benefit is that we can deserialize and then serialize universal-en.txt and compare the results. I've done this, and the results are identical, except for the comment in the YAML frontmatter (which isn't stored in the Sanctorale).

This fixes #60.

mkasberg commented 3 years ago

Let me know what you think! Happy to work with you on any changes needed :slightly_smiling_face:

igneus commented 3 years ago

One more thing: there should be a simple integration test making sure that (non-empty) output of SanctoraleWriter is accepted by SanctoraleLoader.

igneus commented 3 years ago

Thank you very much, merging.