<commit_before>module Traktor
  class Client
    # This will parse the result from the webservice to whatever it needs to be.
    class Parser
      def self.parse(response)

        # Return nil if the result is false.
        return nil if response == 'false'

        # If the response is empty return an empty array.
        return [] if response.size == 0

        # Parse it from JSON first
        response = JSON.parse(response)

        if response.is_a? Array
          # We should return either a collection of Movie or Show objects.
          if response[0]['show'] # So it's shows eeej?
            shows = {}
            response.each do |o|
              show = build_single_show(o)
              unless shows[show.imdb_id.to_sym]
                shows[show.imdb_id.to_sym] = show
              else
                shows[show.imdb_id.to_sym].episodes << show.episodes.first
              end
            end

            return shows.values # Neej it's movies!
          elsif response[0]['movie']
            response.map {|o| build_single_movie(o)}
          end
        elsif response['type'] # If we have a type we know it's either a movie or a show.
          case response['type'].downcase
          when 'movie'
            build_single_movie(response)
          when 'episode'
            build_single_show(response)
          end
        end
      end

      def self.build_single_show(hash)
        show = Show.new(hash['show']['title'], hash['show']['url'], hash['show']['imdb_id'], hash['show']['tvdb_id'])<commit_msg>Close issue #2. Shows can lack imdb_id.<commit_after>module Traktor
  class Client
    # This will parse the result from the webservice to whatever it needs to be.
    class Parser
      def self.parse(response)

        # Return nil if the result is false.
        return nil if response == 'false'

        # If the response is empty return an empty array.
        return [] if response.size == 0

        # Parse it from JSON first
        response = JSON.parse(response)

        if response.is_a? Array
          # We should return either a collection of Movie or Show objects.
          if response[0]['show'] # So it's shows eeej?
            shows = {}
            response.each do |o|
              show = build_single_show(o)
              unless shows[show.url]
                shows[show.url] = show
              else
                shows[show.url].episodes << show.episodes.first
              end
            end

            return shows.values # Neej it's movies!
          elsif response[0]['movie']
            response.map {|o| build_single_movie(o)}
          end
        elsif response['type'] # If we have a type we know it's either a movie or a show.
          case response['type'].downcase
          when 'movie'
            build_single_movie(response)
          when 'episode'
            build_single_show(response)
          end
        end
      end

      def self.build_single_show(hash)
        show = Show.new(hash['show']['title'], hash['show']['url'], hash['show']['imdb_id'], hash['show']['tvdb_id'])
{'fraction_non_alphanumeric': 0.0940032414910859, 'fraction_numerical': 0.00226904376012966, 'mean_word_length': 1.8363970588235294, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1180802', 'n_tokens_mistral': 864, 'n_tokens_neox': 835, 'n_words': 273}