Sha256: 3d4b54818cb61da1336e9eb34f4ade9ac2e2ed92876f897ac2797346cf220398

Contents?: true

Size: 774 Bytes

Versions: 6

Compression:

Stored size: 774 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).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

6 entries across 6 versions & 1 rubygems

Version Path
link_thumbnailer-3.2.0 lib/link_thumbnailer/image_parser.rb
link_thumbnailer-3.1.2 lib/link_thumbnailer/image_parser.rb
link_thumbnailer-3.1.1 lib/link_thumbnailer/image_parser.rb
link_thumbnailer-3.1.0 lib/link_thumbnailer/image_parser.rb
link_thumbnailer-3.0.3 lib/link_thumbnailer/image_parser.rb
link_thumbnailer-3.0.2 lib/link_thumbnailer/image_parser.rb