Sha256: c4802623dfe2426db278a4f5cd857129e6a97bea0f058e6a0cb663dcc3808d4a

Contents?: true

Size: 782 Bytes

Versions: 3

Compression:

Stored size: 782 Bytes

Contents

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
      end

      def size
        [0, 0]
      end

      def type
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
link_thumbnailer-3.3.1 lib/link_thumbnailer/image_parser.rb
link_thumbnailer-3.3.0 lib/link_thumbnailer/image_parser.rb
link_thumbnailer-3.2.1 lib/link_thumbnailer/image_parser.rb