<commit_before>class IcalController < ApplicationController
  GABBA_MAPPING = {
    general: "iCal",
    personalized: "iCal-personalized",
    like_welcome_page: "iCal-not-hated"
  }

  before_filter :set_calendar_headers
  before_filter :gabba,
    only: GABBA_MAPPING.keys,
    if: ->{ Rails.env.production? }
  rescue_from ActiveRecord::RecordNotFound, with: :render_empty

  def general
    render_events SingleEvent.where(occurrence: time_range)
  end

  def personalized
    render_events user.single_events.where(occurrence: time_range)
  end

  def like_welcome_page
    render_events SingleEvent.where(occurrence: time_range).for_user(user)
  end

  def for_single_event
    render_events SingleEvent.find(params[:id])
  end

  def for_event
    render_events Event.find(params[:id]).single_events
  end

  def for_tag
    render_events SingleEvent.only_tagged_with(params[:id])
  end

  private

  def set_calendar_headers
    response.headers["Content-Type"] = "text/calendar; charset=UTF-8"
  end

  def render_events(events)
    ri_cal = RiCal.Calendar
    ri_cal.events.push *events.to_a.map(&:to_ri_cal_event)
    render text: ri_cal
  end

  def render_empty
    render_events []
  end

  def gabba
    gabba = Gabba::Gabba.new "UA-954244-12", "hcking.de"
    gabba.event "Event", GABBA_MAPPING[params[:action].to_sym]
  end

  def time_range
    Date.today..(Date.today + 8.weeks)
  end

  def user
    User.find_by_guid(params[:guid]) || raise(ActiveRecord::RecordNotFound)
  end

end
<commit_msg>fixed ical rendering of single events #156<commit_after>class IcalController < ApplicationController
  GABBA_MAPPING = {
    general: "iCal",
    personalized: "iCal-personalized",
    like_welcome_page: "iCal-not-hated"
  }

  before_filter :set_calendar_headers
  before_filter :gabba,
    only: GABBA_MAPPING.keys,
    if: ->{ Rails.env.production? }
  rescue_from ActiveRecord::RecordNotFound, with: :render_empty

  def general
    render_events SingleEvent.where(occurrence: time_range)
  end

  def personalized
    render_events user.single_events.where(occurrence: time_range)
  end

  def like_welcome_page
    render_events SingleEvent.where(occurrence: time_range).for_user(user)
  end

  def for_single_event
    render_event SingleEvent.find(params[:id])
  end

  def for_event
    render_events Event.find(params[:id]).single_events
  end

  def for_tag
    render_events SingleEvent.only_tagged_with(params[:id])
  end

  private

  def set_calendar_headers
    response.headers["Content-Type"] = "text/calendar; charset=UTF-8"
  end

  def render_event(event)
    ri_cal = RiCal.Calendar
    ri_cal.events.push event.to_ri_cal_event
    render text: ri_cal
  end

  def render_events(events)
    ri_cal = RiCal.Calendar
    ri_cal.events.push *events.to_a.map(&:to_ri_cal_event)
    render text: ri_cal
  end

  def render_empty
    render_events []
  end

  def gabba
    gabba = Gabba::Gabba.new "UA-954244-12", "hcking.de"
    gabba.event "Event", GABBA_MAPPING[params[:action].to_sym]
  end

  def time_range
    Date.today..(Date.today + 8.weeks)
  end

  def user
    User.find_by_guid(params[:guid]) || raise(ActiveRecord::RecordNotFound)
  end

end

{'fraction_non_alphanumeric': 0.09435736677115987, 'fraction_numerical': 0.007210031347962382, 'mean_word_length': 3.9781591263650546, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3932567', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1100, 'n_words': 210}