Class: Riiif::File

Inherits:
Object
  • Object
show all
Defined in:
app/models/riiif/file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_path, tempfile = nil) ⇒ File

Returns a new instance of File.

Parameters:

  • input_path (String)

    The location of an image file



9
10
11
12
# File 'app/models/riiif/file.rb', line 9

def initialize(input_path, tempfile = nil)
  @path = input_path
  @tempfile = tempfile # ensures that the tempfile will stick around until this file is garbage collected.
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'app/models/riiif/file.rb', line 3

def path
  @path
end

Class Method Details

.create(ext = nil, _validate = true, &block) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'app/models/riiif/file.rb', line 23

def self.create(ext = nil, _validate = true, &block)
  tempfile = Tempfile.new(['mini_magick', ext.to_s.downcase])
  tempfile.binmode
  block.call(tempfile)
  tempfile.close
  image = new(tempfile.path, tempfile)
ensure
  tempfile.close if tempfile
end

.read(stream, ext) ⇒ Object



14
15
16
17
18
19
20
# File 'app/models/riiif/file.rb', line 14

def self.read(stream, ext)
  create(ext) do |f|
    while chunk = stream.read(8192)
      f.write(chunk)
    end
  end
end

Instance Method Details

#extract(transformation) ⇒ Object

Parameters:



35
36
37
38
# File 'app/models/riiif/file.rb', line 35

def extract(transformation)
  command = command_factory.build(path, transformation)
  execute(command)
end

#infoObject



40
41
42
# File 'app/models/riiif/file.rb', line 40

def info
  @info ||= info_extractor_class.new(path).extract
end