View Source Naiveical.Extractor (Naiveical v1.0.0)
This module allows the extraction of parts of a icalendar text.
Link to this section Summary
Functions
Detects the component type from iCalendar data.
Extracts a specific attribute from a list of attributes.
Extract a single content line from an icalendar text split into tag, properties, and values. It returns a tuple with {tag-name, properties, value}.
Extract a single date content line from an icalendar text. It returns a the datetime object.
Extract a single datetime content line from an icalendar text. It returns a the datetime object.
Extract a single datetime content line from an icalendar text. It returns a the datetime object.
Extract a raw single content line from an icalendar text.
Extract parts of an icalender text, such as all VALARMs. ## Examples
Remove sections of an icalender text, such as remove all VALARMs from a VEVENT.
Link to this section Types
Link to this section Functions
Detects the component type from iCalendar data.
Returns an atom representing the component type found in the iCalendar data. Priority order: :vfreebusy > :vtodo > :vjournal > :vevent (default)
examples
Examples
iex> Naiveical.Extractor.detect_component_type("BEGIN:VCALENDAR\nBEGIN:VEVENT\nEND:VEVENT\nEND:VCALENDAR")
:vevent
iex> Naiveical.Extractor.detect_component_type("BEGIN:VCALENDAR\nBEGIN:VTODO\nEND:VTODO\nEND:VCALENDAR")
:vtodo
iex> Naiveical.Extractor.detect_component_type("BEGIN:VCALENDAR\nEND:VCALENDAR")
:vevent
Extracts a specific attribute from a list of attributes.
@spec extract_contentline_by_tag(String.t() | nil, String.t()) :: content_line()
Extract a single content line from an icalendar text split into tag, properties, and values. It returns a tuple with {tag-name, properties, value}.
## Examples:
iex> Naiveical.Extractor.extract_contentline_by_tag("BEGIN:XX\nBEGIN:YY\nA:aa\nB:bb\nEND:YY\nBEGIN:YY\nC:cc\nD:dd\nEND:YY\nEND:XX", "A") {"A","","aa"}
iex> Naiveical.Extractor.extract_contentline_by_tag("BEGIN:XX\nBEGIN:YY\nA:aa\nB:bb\nEND:YY\nBEGIN:YY\nC:cc\nD:dd\nEND:YY\nEND:XX", "ZZZ") {"ZZZ","",nil}
@spec extract_date_contentline_by_tag!(String.t(), String.t()) :: NaiveDateTime.t()
Extract a single date content line from an icalendar text. It returns a the datetime object.
Basically, it tries to parse the extracted text as a date object
## Examples:
iex> Naiveical.Extractor.extract_date_contentline_by_tag!("BEGIN:XX\nBEGIN:YY\nA:aa\nB:bb\nDTSTART;TZID=Europe/Berlin:20210422\nEND:YY\nBEGIN:YY\nC:cc\nD:dd\nEND:YY\nEND:XX", "DTSTART")
@spec extract_datetime_contentline_by_tag(String.t(), String.t()) :: {:ok, DateTime.t()} | {:error, term()} | nil
Extract a single datetime content line from an icalendar text. It returns a the datetime object.
Basically, it tries to parse the extracted text as a datetime object with the given timezone information
## Examples:
iex> Naiveical.Extractor.extract_datetime_contentline_by_tag("BEGIN:XX\nBEGIN:YY\nA:aa\nB:bb\nDTSTART;TZID=Europe/Berlin:20210422T150000\nEND:YY\nBEGIN:YY\nC:cc\nD:dd\nEND:YY\nEND:XX", "DTSTART")
@spec extract_datetime_contentline_by_tag!(String.t(), String.t()) :: DateTime.t()
Extract a single datetime content line from an icalendar text. It returns a the datetime object.
Basically, it tries to parse the extracted text as a datetime object with the given timezone information
## Examples:
iex> Naiveical.Extractor.extract_datetime_contentline_by_tag!("BEGIN:XX\nBEGIN:YY\nA:aa\nB:bb\nDTSTART;TZID=Europe/Berlin:20210422T150000\nEND:YY\nBEGIN:YY\nC:cc\nD:dd\nEND:YY\nEND:XX", "DTSTART")
Extract a raw single content line from an icalendar text.
## Examples:
iex> Naiveical.Extractor.extract_raw_contentline_by_tag("BEGIN:XX\nBEGIN:YY\nA;xx:aa\nB:bb\nEND:YY\nBEGIN:YY\nC:cc\nD:dd\nEND:YY\nEND:XX", "A") "A;xx:aa"
iex> Naiveical.Extractor.extract_raw_contentline_by_tag("BEGIN:XX\nBEGIN:YY\nA:aa\nB:bb\nEND:YY\nBEGIN:YY\nC:cc\nD:dd\nEND:YY\nEND:XX", "ZZZ") nil
Extract parts of an icalender text, such as all VALARMs. ## Examples:
iex> Naiveical.Extractor.extract_sections_by_tag("BEGIN:XX\nBEGIN:YY\nA:aa\nB:bb\nEND:YY\nBEGIN:YY\nC:cc\nD:dd\nEND:YY\nEND:XX", "XX") ["BEGIN:XX\r\nBEGIN:YY\r\nA:aa\r\nB:bb\r\nEND:YY\r\nBEGIN:YY\r\nC:cc\r\nD:dd\r\nEND:YY\r\nEND:XX"]
iex> Naiveical.Extractor.extract_sections_by_tag("BEGIN:XX\r\nBEGIN:YY\r\nA:aa\r\nB:bb\r\nEND:YY\r\nBEGIN:YY\r\nC:cc\r\nD:dd\r\nEND:YY\r\nEND:XX", "YY") ["BEGIN:YY\r\nA:aa\r\nB:bb\r\nEND:YY", "BEGIN:YY\r\nC:cc\r\nD:dd\r\nEND:YY"]
Remove sections of an icalender text, such as remove all VALARMs from a VEVENT.
The reason of this is to allow the correct extraction of the content lines. If, for example, a VEVENT also contains a VALARM with a description, but the VEVENT does not contain a description, the function extract_contentline_by_tag would fetch the description of the VALARM instead of returning nil.
## Examples:
iex> Naiveical.Extractor.remove_sections_by_tag("BEGIN:XX\nBEGIN:YY\nA:aa\nB:bb\nEND:YY\nEND:XX", "YY") "BEGIN:XX\nEND:XX"
iex> Naiveical.Extractor.remove_sections_by_tag("BEGIN:XX\nBEGIN:YY\nA:aa\nB:bb\nEND:YY\naaaa:bbbb\nBEGIN:YY\nC:cc\nD:dd\nEND:YY\nEND:XX", "NOTEXIST") "BEGIN:XX\nBEGIN:YY\nA:aa\nB:bb\nEND:YY\naaaa:bbbb\nBEGIN:YY\nC:cc\nD:dd\nEND:YY\nEND:XX"