<commit_before>module Queries
  class Organisations

    attr_reader :query_term, :organisations, :params
    def initialize(query_term, organisations, params)
      @query_term = query_term
      @organisations = organisations
      @params = params
    end

    def search_by_keyword_and_category
      categories = what_ids + who_ids + how_ids
      organisations.search_by_keyword(
        query_term
      ).filter_by_categories(
        categories
      )
    end


    def what_id
      params.require(:what).permit(:id)[:id]
    end

    def how_id
      params.require(:how).permit(:id)[:id]
    end

    def who_id
      params.require(:who).permit(:id)[:id]
    end

    def what_ids
      id = params.require(:what).permit(:id).values
      if id.first.empty?
        Category.what_they_do.select(:id)
      else
        id
      end
    end

    def who_ids
      id = params.require(:who).permit(:id).values
      if id.first.empty?
        Category.who_they_help.select(:id)
      else
        id
      end
    end

    def how_ids
      id = params.require(:how).permit(:id).values
      if id.first.empty?
        Category.how_they_help.select(:id)
      else
        id
      end
    end

  end

end
<commit_msg>refactors Queries::Organisation to use #what_id, #who_id, and #how_id internally<commit_after>module Queries
  class Organisations

    attr_reader :query_term, :organisations, :params
    def initialize(query_term, organisations, params)
      @query_term = query_term
      @organisations = organisations
      @params = params
    end

    def search_by_keyword_and_category
      categories = what_ids + who_ids + how_ids
      organisations.search_by_keyword(
        query_term
      ).filter_by_categories(
        categories
      )
    end


    def what_id
      @what_id ||= params.require(:what).permit(:id).fetch(:id)
    end

    def how_id
      @how_id ||= params.require(:how).permit(:id).fetch(:id)
    end

    def who_id
      @who_id ||= params.require(:who).permit(:id).fetch(:id)
    end

    def what_ids
      if what_id.empty?
        Category.what_they_do.select(:id)
      else
        Array.wrap(what_id)
      end
    end

    def who_ids
      if who_id.empty?
        Category.who_they_help.select(:id)
      else
        Array.wrap(who_id)
      end
    end

    def how_ids
      if how_id.empty?
        Category.how_they_help.select(:id)
      else
        Array.wrap(how_id)
      end
    end

  end

end

{'fraction_non_alphanumeric': 0.09142394822006472, 'fraction_numerical': 0.0, 'mean_word_length': 2.2033678756476682, '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': '655079', 'n_tokens_mistral': 815, 'n_tokens_neox': 788, 'n_words': 159}