<commit_before>module Locomotive
  class Meritas::Api::ContentEntry

    attr_reader :params, :content_type, :site
    attr_accessor :content_entries

    MERITAS_CUSTOM_CONTENT_TYPES = %w(events)

    def initialize(args = {})
      @content_entries = args[:content_entries]
      @params = args[:params]
      @content_type = args[:content_type]
      @site = args[:site]
    end

    def entries
      return @content_entries unless MERITAS_CUSTOM_CONTENT_TYPES.include?(slug)
      send("#{slug}_entries")
    end

    private

      def slug
        @content_type.slug.downcase
      end

      def events_entries
        filter_by_date_range if start_date.present? && end_date.present?
        filter_by_function if params[:function_id].present?
        filter_by_group if params[:group_id].present?
        return @content_entries
      end

      def start_date
        @start_date ||= params[:start_date]
      end

      def end_date
        @end_date ||= params[:start_date]
      end

      def filter_by_date_range
        start_date = Date.parse(params[:start_date])
        end_date = Date.parse(params[:end_date])
        @content_entries = @content_entries.where(:start_time.gte => start_date, :end_time.lte => end_date)
      end

      # GROUP
      def filter_by_group
        @content_entries = @content_entries.where(group: params[:group_id])
      end

      def group_content_type
        @group_content_type ||= @site.content_types.where(slug: "groups").first
      end

      # FUNCTION
      def filter_by_function
        @content_entries = @content_entries.where(function: params[:function_id])
      end

      def function_content_type
        @function_content_type ||= @site.content_types.where(slug: "functions").first
      end

  end
end<commit_msg>scoping events to public, portal, or both<commit_after>module Locomotive
  class Meritas::Api::ContentEntry

    attr_reader :params, :content_type, :site
    attr_accessor :content_entries

    MERITAS_CUSTOM_CONTENT_TYPES = %w(events)

    def initialize(args = {})
      @content_entries = args[:content_entries]
      @params = args[:params]
      @content_type = args[:content_type]
      @site = args[:site]
    end

    def entries
      return @content_entries unless MERITAS_CUSTOM_CONTENT_TYPES.include?(slug)
      send("#{slug}_entries")
    end

    private

      def slug
        @content_type.slug.downcase
      end

      def events_entries
        filter_by_date_range if start_date.present? && end_date.present?
        filter_by_function if params[:function_id].present?
        filter_by_group if params[:group_id].present?
        filter_by_publish_to if params[:calendar].present?
        return @content_entries
      end

      def start_date
        @start_date ||= params[:start_date]
      end

      def end_date
        @end_date ||= params[:start_date]
      end

      def filter_by_date_range
        start_date = Date.parse(params[:start_date])
        end_date = Date.parse(params[:end_date])
        @content_entries = @content_entries.where(:start_time.gte => start_date, :end_time.lte => end_date)
      end

      # GROUP
      def filter_by_group
        @content_entries = @content_entries.where(group: params[:group_id])
      end

      def group_content_type
        @group_content_type ||= @site.content_types.where(slug: "groups").first
      end

      # FUNCTION
      def filter_by_function
        @content_entries = @content_entries.where(function: params[:function_id])
      end

      def function_content_type
        @function_content_type ||= @site.content_types.where(slug: "functions").first
      end

      #FUNCTION
      def filter_by_publish_to
        calendar_hash = {"public" => ["Public Calendar", "All Calendars"], "portal" => ["Portal Calendar", "All Calendars"]}
        array = calendar_hash[params[:calendar]]
        field = @content_type.entries_custom_fields.where(name: "publish_to").first
        return unless field.present?
        ids = field.select_options.map {|f| array.include?(f.name) ? f._id : nil }.compact
        @content_entries = @content_entries.where(:publish_to_id.in => ids)
      end

  end
end
{'fraction_non_alphanumeric': 0.09767775915728992, 'fraction_numerical': 0.0, 'mean_word_length': 2.9377945334590008, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '1556377', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1273, 'n_words': 243}