<commit_before>require 'image_info'

module LinkThumbnailer
  class ImageParser

    attr_reader :images

    def initialize(urls)
      @images = perform? ? ::ImageInfo.from(urls, max_concurrency: max_concurrency) : Array(urls).map(&method(:build_default_image))
    end

    def size
      images.first.size
    end

    def type
      images.first.type
    end

    private

    def build_default_image(uri)
      NullImage.new(uri)
    end

    def perform?
      ::LinkThumbnailer.page.config.image_stats
    end

    def max_concurrency
      ::LinkThumbnailer.page.config.max_concurrency
    end

    class NullImage
      attr_reader :uri

      def initialize(uri)
        @uri = uri<commit_msg>Avoid nil urls in image parser<commit_after>require 'image_info'

module LinkThumbnailer
  class ImageParser

    attr_reader :images

    def initialize(urls)
      @images = perform? ? ::ImageInfo.from(urls, max_concurrency: max_concurrency) : Array(urls).compact.map(&method(:build_default_image))
    end

    def size
      images.first.size
    end

    def type
      images.first.type
    end

    private

    def build_default_image(uri)
      NullImage.new(uri)
    end

    def perform?
      ::LinkThumbnailer.page.config.image_stats
    end

    def max_concurrency
      ::LinkThumbnailer.page.config.max_concurrency
    end

    class NullImage
      attr_reader :uri

      def initialize(uri)
        @uri = uri
{'fraction_non_alphanumeric': 0.07606420097697139, 'fraction_numerical': 0.0, 'mean_word_length': 2.6863753213367607, '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': '6066857', 'n_tokens_mistral': 461, 'n_tokens_neox': 445, 'n_words': 96}