class Dimscan::BaseScanner

The abstract base class

Public Class Methods

new(url) click to toggle source
# File lib/dimscan/base_scanner.rb, line 11
def initialize(url)
  @bytes = HTTPByteEnumerator.new(url)
  @fallback_file = `mktemp`.chomp
end

Public Instance Methods

scan_dimensions() click to toggle source
# File lib/dimscan/base_scanner.rb, line 16
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 Instance Methods

scan(_bytes) click to toggle source
# File lib/dimscan/base_scanner.rb, line 31
def scan(_bytes)
  fail AbstractError, 'not implemented'
end