Sha256: 54a1f5bf3c31965e7c932f22d9613eb7c11948ded1841ae2fbec0d1d1e6331f8

Contents?: true

Size: 750 Bytes

Versions: 2

Compression:

Stored size: 750 Bytes

Contents

require 'uri'
require 'dimscan/http_byte_enumerator'
require 'mini_magick'
require 'abstractize'

module Dimscan
  # The abstract base class
  class BaseScanner
    include Abstractize

    def initialize(url)
      @bytes = HTTPByteEnumerator.new(url)
      @fallback_file = `mktemp`.chomp
    end

    def scan_dimensions
      dimensions = nil
      File.open(@fallback_file, 'wb') do |file|
        dimensions = scan(@bytes.each) { |b| file.write(b) }
      end
      width, height = (
        dimensions || MiniMagick::Image.new(@fallback_file).dimensions
      )

      File.delete(@fallback_file)
      { width: width, height: height }
    end

    protected

    def scan(_bytes)
      fail AbstractError, 'not implemented'
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dimscan-0.2.3 lib/dimscan/base_scanner.rb
dimscan-0.2.2 lib/dimscan/base_scanner.rb