Class: Dimscan::BaseScanner
- Inherits:
-
Object
- Object
- Dimscan::BaseScanner
- Includes:
- Abstractize
- Defined in:
- lib/dimscan/base_scanner.rb
Overview
The abstract base class
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(url) ⇒ BaseScanner
constructor
A new instance of BaseScanner.
- #scan_dimensions ⇒ Object
Constructor Details
#initialize(url) ⇒ BaseScanner
Returns a new instance of BaseScanner.
11 12 13 14 |
# File 'lib/dimscan/base_scanner.rb', line 11 def initialize(url) @bytes = HTTPByteEnumerator.new(url) @fallback_file = `mktemp`.chomp end |
Instance Method Details
#scan_dimensions ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# 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 |