Naiveical
With naiveical you can extract parts of an icalendar file and update individual lines. It does not parse the icalendar but rather works directly with pure text. As such it does not prevent you from doing stupid things, such as embedding elements into each other that have no meaning.
The advantage of this approach is to keep the icalendar text as close to the original as possible, with only modifying the changed parts.
Installation
The package available in Hex and can be installed
by adding naiveical to your list of dependencies in mix.exs:
def deps do
[
{:naiveical, "~> 0.1.1"}
]
end
Documentation
Available at HexDocs.
Example
Create a new vcalendar:
ical = Naiveical.Creator.create_vcalendar()
Create a new vtodo:
dtstart = DateTime.now!("Etc/UTC")
due = DateTime.now!("Etc/UTC")
todo = Naiveical.Creator.create_vtodo("vtodo example", dtstart, due)
Create a new valert:
alarm = Naiveical.Creator.create_valarm("Ring the bell", "-PT15M")
alarm2 = Naiveical.Creator.create_valarm("Ring the bell", "-PT5M")
Assemble all together:
{:ok, todo} = Naiveical.Modificator.insert_into(todo, alarm, "VTODO")
{:ok, todo} = Naiveical.Modificator.insert_into(todo, alarm2, "VTODO")
{:ok, ical} = Naiveical.Modificator.insert_into(ical, todo, "VCALENDAR")
Extract the summary content line:
Naiveical.Extractor.extract_contentline_by_tag(ical, "SUMMARY")
{_tag, _attr, due_str} = Naiveical.Extractor.extract_contentline_by_tag(ical, "DUE")
Naiveical.Helpers.parse_datetime(due_str)
Change the summary:
updated_ical = Naiveical.Modificator.change_value(ical, "summary", "my updated summary")
Extract the alerts:
valarms = Naiveical.Extractor.extract_sections_by_tag(ical, "VALARM")
VTIMEZONE database
The VTIMEZONE database has been compiled by using the vzic utility.
Rationale
The difficulty in parsing the icalendar format is that it is difficult to write a library that can parse and re-create the icalendar file without any data loss. As such it is best to keep the original icalendar file and work directly on the file. This makes working with the access of the individual fields more complicated but keeps the original file intact.