<commit_before>module Almanack
  module Representation
    class IcalFeed
      attr_reader :calendar

      def initialize(calendar)
        @calendar = calendar
      end

      def ical
        @ical ||= begin
          ical_component = RiCal.Calendar

          calendar.events_between(now..lookahead).each do |event|
            ical_event = RiCal.Event
            ical_event.summary = event.title
            ical_event.dtstart = event.start_date.utc
            ical_event.dtend = (event.end_date || event.start_date + default_event_duration ).utc
            ical_event.description = event.description if event.description
            ical_event.location = event.location if event.location

            ical_component.add_subcomponent(ical_event)
          end

          ical_component
        end
      end

      def to_s
        ical.to_s
      end

      def self.from(calendar)
        self.new(calendar).to_s
      end

      private<commit_msg>Refactor Representation::IcalFeed<commit_after>module Almanack
  module Representation
    class IcalFeed
      attr_reader :calendar

      def initialize(calendar)
        @calendar = calendar
      end

      def ical
        @ical ||= ical_calendar
      end

      def to_s
        ical.to_s
      end

      def self.from(calendar)
        self.new(calendar).to_s
      end

      private

      def events
        calendar.events_between(now..lookahead)
      end

      def ical_calendar
        events.each_with_object(RiCal.Calendar) do |event, calendar_component|
          calendar_component.add_subcomponent ical_event_for(event)
        end
      end

      def ical_event_for(event)
        ical_event = RiCal.Event
        ical_event.summary = event.title
        ical_event.dtstart = event.start_date.utc
        ical_event.dtend = (event.end_date || event.start_date + default_event_duration ).utc
        ical_event.description = event.description if event.description
        ical_event.location = event.location if event.location
        ical_event
      end
{'fraction_non_alphanumeric': 0.061764705882352944, 'fraction_numerical': 0.0, 'mean_word_length': 2.083081570996979, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6331942', 'n_tokens_mistral': 584, 'n_tokens_neox': 562, 'n_words': 119}