Class: WaxTasks::Asset

Inherits:
Object
  • Object
show all
Defined in:
lib/wax_tasks/asset.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, pid, variants) ⇒ Asset

Returns a new instance of Asset.



10
11
12
13
14
15
# File 'lib/wax_tasks/asset.rb', line 10

def initialize(path, pid, variants)
  @path     = path
  @pid      = pid
  @id       = asset_id
  @variants = variants
end

Instance Method Details

#asset_idObject



19
20
21
22
23
# File 'lib/wax_tasks/asset.rb', line 19

def asset_id
  id = File.basename(@path, '.*')
  id.prepend "#{@pid}_" unless id == @pid
  id
end

#simple_derivativesObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/wax_tasks/asset.rb', line 27

def simple_derivatives
  @variants.map do |label, width|
    img = MiniMagick::Image.open(@path)
    if width > img.width
      warn Rainbow("Tried to create derivative #{width}px wide, but asset #{@id} for item #{@pid} only has a width of #{img.width}px.").yellow
    else
      img.resize width
    end

    img.format 'jpg'
    Derivative.new("#{@id}/#{label}.jpg", label, img)
  end
end

#to_iiif_image_record(is_only, index, base_opts) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/wax_tasks/asset.rb', line 43

def to_iiif_image_record(is_only, index, base_opts)
  opts = base_opts.clone
  opts[:is_primary]    = index.zero?
  opts[:section_label] = "Page #{index + 1}" unless is_only
  opts[:path]          = @path
  opts[:manifest_id]   = @pid
  opts[:id]            = @id

  WaxIiif::ImageRecord.new(opts)
end