class Jekyll::IcalTag::Event

Constants

URL_REGEX

Attributes

all_properties[R]
ical_event[R]

Public Class Methods

new(ical_event) click to toggle source
# File lib/jekyll-ical-tag/event.rb, line 32
def initialize(ical_event)
  @ical_event = ical_event
  setup_all_properties!
  setup_property_accessor_methods!
end

Public Instance Methods

attendees() click to toggle source
# File lib/jekyll-ical-tag/event.rb, line 50
def attendees
  ical_event.attendee.map(&:to_s).map { |a| a.slice!("mailto:"); a }
end
description_urls() click to toggle source
# File lib/jekyll-ical-tag/event.rb, line 54
def description_urls
  return [] unless description

  @description_urls ||= description.scan(URL_REGEX).to_a
end
simple_html_description() click to toggle source
# File lib/jekyll-ical-tag/event.rb, line 40
def simple_html_description
  @simple_html_description ||= begin
    description.clone.tap do |description|
      description_urls.each do |url|
        description.gsub! url, %(<a href='#{url}'>#{url}</a>)
      end
    end
  end
end

Private Instance Methods

setup_all_properties!() click to toggle source
# File lib/jekyll-ical-tag/event.rb, line 64
def setup_all_properties!
  @all_properties ||= begin
    props = {}

    # RFC 5545 Properties
    ical_event.class.properties.each do |property|
      props[property] = ical_event.property(property)
    end

    # custom properties
    props = props.merge(ical_event.custom_properties)

    # Ensure all arrays get flattened to utf8 encoded strings
    # Ensure all event values are utf8 encoded strings
    # Ensure times (from dates)
    # Ensure present
    props.transform_values! do |value|
      new_value =
        case value
        when Array, Icalendar::Values::Array
          value.join("\n").force_encoding("UTF-8")
        when String, Icalendar::Values::Text
          value.force_encoding("UTF-8")
        when Date, Icalendar::Values::DateTime
          value.to_time
        when Icalendar::Values::Uri
          value.to_s
        else
          value
        end

      new_value.presence
    end

    props
  end
end
setup_property_accessor_methods!() click to toggle source
# File lib/jekyll-ical-tag/event.rb, line 102
def setup_property_accessor_methods!
  all_properties.each do |prop, value|
    define_singleton_method prop do
      all_properties[prop]
    end
  end
end