Sha256: 2e2c617b4362713b84e16a1ccc26d7a2e35f419de8a274229a51b8632b275b76

Contents?: true

Size: 1.26 KB

Versions: 28

Compression:

Stored size: 1.26 KB

Contents

module Workarea
  module Admin
    class ReleasesFeedViewModel < ApplicationViewModel
      delegate :to_ical, to: :calendar

      def calendar
        @calendar ||= Icalendar::Calendar.new.tap do |calendar|
          calendar.add_timezone(calendar_timezone)

          calendar.x_wr_calname = I18n.t(
            'workarea.admin.releases.feed.name',
            site_name: Workarea.config.site_name
          )

          releases.each do |release|
            calendar.event do |event|
              event.dtstart = format_date(release.starts_at)
              event.dtend = format_date(release.ends_at)
              event.summary = release.name
              event.description = release.description
            end
          end

          calendar
        end
      end

      private

      def timezone_id
        Time.zone.tzinfo.identifier
      end

      def calendar_timezone
        TZInfo::Timezone.get(timezone_id).ical_timezone(Time.current)
      end

      def releases
        @releases ||= Admin::ReleaseEventViewModel.wrap(
          Release.published_within(Time.current, 1.year.from_now)
        )
      end

      def format_date(time)
        return unless time.present?
        Icalendar::Values::DateTime.new(time, tzid: timezone_id)
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
workarea-admin-3.5.27 app/view_models/workarea/admin/releases_feed_view_model.rb
workarea-admin-3.5.26 app/view_models/workarea/admin/releases_feed_view_model.rb
workarea-admin-3.5.25 app/view_models/workarea/admin/releases_feed_view_model.rb
workarea-admin-3.5.23 app/view_models/workarea/admin/releases_feed_view_model.rb
workarea-admin-3.5.22 app/view_models/workarea/admin/releases_feed_view_model.rb
workarea-admin-3.5.21 app/view_models/workarea/admin/releases_feed_view_model.rb
workarea-admin-3.5.20 app/view_models/workarea/admin/releases_feed_view_model.rb
workarea-admin-3.5.19 app/view_models/workarea/admin/releases_feed_view_model.rb
workarea-admin-3.5.18 app/view_models/workarea/admin/releases_feed_view_model.rb
workarea-admin-3.5.17 app/view_models/workarea/admin/releases_feed_view_model.rb
workarea-admin-3.5.16 app/view_models/workarea/admin/releases_feed_view_model.rb
workarea-admin-3.5.15 app/view_models/workarea/admin/releases_feed_view_model.rb
workarea-admin-3.5.14 app/view_models/workarea/admin/releases_feed_view_model.rb
workarea-admin-3.5.13 app/view_models/workarea/admin/releases_feed_view_model.rb
workarea-admin-3.5.12 app/view_models/workarea/admin/releases_feed_view_model.rb
workarea-admin-3.5.11 app/view_models/workarea/admin/releases_feed_view_model.rb
workarea-admin-3.5.10 app/view_models/workarea/admin/releases_feed_view_model.rb
workarea-admin-3.5.9 app/view_models/workarea/admin/releases_feed_view_model.rb
workarea-admin-3.5.8 app/view_models/workarea/admin/releases_feed_view_model.rb
workarea-admin-3.5.7 app/view_models/workarea/admin/releases_feed_view_model.rb