Class: Textus::Step::Builtin::IcalEventsFetch

Inherits:
Fetch show all
Defined in:
lib/textus/step/builtin/ical_events_fetch.rb

Instance Attribute Summary

Attributes inherited from Textus::Step::Base

#name

Instance Method Summary collapse

Methods inherited from Fetch

required_kwargs

Methods inherited from Textus::Step::Base

kind, required_kwargs, step_name

Instance Method Details

#call(config:, args:) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/textus/step/builtin/ical_events_fetch.rb', line 10

def call(config:, args:, **)
  _ = args
  events_list = []
  current = nil
  config["bytes"].to_s.each_line do |line|
    line = line.strip
    case line
    when "BEGIN:VEVENT" then current = {}
    when "END:VEVENT"
      events_list << current if current
      current = nil
    when /\A(SUMMARY|DTSTART|DTEND|UID|LOCATION|DESCRIPTION):(.*)\z/
      current[Regexp.last_match(1).downcase] = Regexp.last_match(2) if current
    end
  end
  { _meta: {}, body: YAML.dump(events_list) }
end