Class: WaxTasks::Asset

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, pid, variants) ⇒ Asset

Returns a new instance of Asset.



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

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

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/wax_tasks/asset.rb', line 9

def id
  @id
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/wax_tasks/asset.rb', line 9

def path
  @path
end

Instance Method Details

#asset_idObject



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

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

#simple_derivativesObject



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

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



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

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
  opts[:variants]      = @variants

  WaxIiif::ImageRecord.new(opts)
end