<commit_before>class Recommendation < ActiveRecord::Base
  has_many :user_recommendations
  has_many :users, through: :user_recommendations

  validates :title, :year, :rated, :released,
            :runtime, :genre, :director, :writer,
            :actors, :plot, :language, :country,
            :awards, :poster, :metascore, :imdb_rating,
            :imdb_ID, :media_type, presence: true

  def self.service
    @service ||= OmdbService.new
  end

  def self.find_or_create_media(title_or_id)
    if not_matching_movie_in_database?(title_or_id)
      make_a_request_and_build_recommendation(title_or_id)
    else
      find_by_title_or_imdb_id(title_or_id)
    end
  end

  def self._build_recommendation(request_from_omdb)
    create!(RecommendationParser.new(request_from_omdb).clean_up)
  end

  private

  def self.movie_found?
    @request_from_omdb["Response"] != "False"
  end

  def self.not_adult_content?
    !@request_from_omdb["Genre"].include?("Adult")
  end

  def self.not_matching_movie_in_database?(title_or_id)
    not_matching_by_title?(title_or_id) && not_matching_by_imdb_id?(title_or_id)
  end

  def self.find_by_title_or_imdb_id(title_or_id)
    if not_matching_by_title?(title_or_id)
      Recommendation.find_by(imdb_ID: title_or_id)
    else
      Recommendation.find_by("title LIKE ?", "%#{title_or_id.downcase}%")
    end
  end

  def self.not_matching_by_title?(title_or_id)
    Recommendation.where("title LIKE ?", "%#{title_or_id.downcase}%").empty?
  end

  def self.not_matching_by_imdb_id?(imdb_id)
    !Recommendation.exists?(imdb_ID: imdb_id)
  end

  def self.make_a_request_and_build_recommendation(title_or_id)
    @request_from_omdb = service.media(title_or_id)

    if movie_found? && not_adult_content?
      _build_recommendation(@request_from_omdb)<commit_msg>removed underscore method name<commit_after>class Recommendation < ActiveRecord::Base
  has_many :user_recommendations
  has_many :users, through: :user_recommendations

  validates :title, :year, :rated, :released,
            :runtime, :genre, :director, :writer,
            :actors, :plot, :language, :country,
            :awards, :poster, :metascore, :imdb_rating,
            :imdb_ID, :media_type, presence: true

  def self.service
    @service ||= OmdbService.new
  end

  def self.find_or_create_media(title_or_id)
    if not_matching_movie_in_database?(title_or_id)
      make_a_request_and_build_recommendation(title_or_id)
    else
      find_by_title_or_imdb_id(title_or_id)
    end
  end

  def self.build_recommendation(request_from_omdb)
    create!(RecommendationParser.new(request_from_omdb).clean_up)
  end

  private

  def self.movie_found?
    @request_from_omdb["Response"] != "False"
  end

  def self.not_adult_content?
    !@request_from_omdb["Genre"].include?("Adult")
  end

  def self.not_matching_movie_in_database?(title_or_id)
    not_matching_by_title?(title_or_id) && not_matching_by_imdb_id?(title_or_id)
  end

  def self.find_by_title_or_imdb_id(title_or_id)
    if not_matching_by_title?(title_or_id)
      Recommendation.find_by(imdb_ID: title_or_id)
    else
      Recommendation.find_by("title LIKE ?", "%#{title_or_id.downcase}%")
    end
  end

  def self.not_matching_by_title?(title_or_id)
    Recommendation.where("title LIKE ?", "%#{title_or_id.downcase}%").empty?
  end

  def self.not_matching_by_imdb_id?(imdb_id)
    !Recommendation.exists?(imdb_ID: imdb_id)
  end

  def self.make_a_request_and_build_recommendation(title_or_id)
    @request_from_omdb = service.media(title_or_id)

    if movie_found? && not_adult_content?
      build_recommendation(@request_from_omdb)
{'fraction_non_alphanumeric': 0.1001926782273603, 'fraction_numerical': 0.0, 'mean_word_length': 4.642857142857143, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1048729', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1351, 'n_words': 190}