class WaxTasks::Item

Attributes

iiif_config[RW]
pid[R]
record[RW]

Public Class Methods

new(path, variants) click to toggle source
# File lib/wax_tasks/item.rb, line 12
def initialize(path, variants)
  @path            = path
  @variants        = variants
  @type            = type
  @pid             = File.basename @path, '.*'
  @assets          = assets
end

Public Instance Methods

accepted_image_formats() click to toggle source
# File lib/wax_tasks/item.rb, line 22
def accepted_image_formats
  %w[.png .jpg .jpeg .tiff .tif]
end
assets() click to toggle source
# File lib/wax_tasks/item.rb, line 46
def assets
  if accepted_image_formats.include? @type
    [Asset.new(@path, @pid, @variants)]
  elsif @type == 'dir'
    paths = Dir.glob("#{@path}/*{#{accepted_image_formats.join(',')}}").sort
    paths.map { |p| Asset.new(p, @pid, @variants) }
  else
    []
  end
end
attribution() click to toggle source
# File lib/wax_tasks/item.rb, line 88
def attribution
  attribution_key = @iiif_config.dig 'attribution'
  @record.hash.dig attribution_key if attribution_key && @record
end
base_opts() click to toggle source
# File lib/wax_tasks/item.rb, line 106
def base_opts
  opts = { label: label }
  return opts unless @iiif_config

  opts[:logo]        = logo if logo
  opts[:description] = description.to_s if description
  opts[:attribution] = attribution.to_s if attribution
  opts
end
description() click to toggle source
# File lib/wax_tasks/item.rb, line 81
def description
  description_key = @iiif_config&.dig 'description'
  @record.hash.dig description_key if description_key && @record
end
iiif_image_records() click to toggle source
# File lib/wax_tasks/item.rb, line 95
def iiif_image_records
  opts = base_opts.clone
  is_only = @assets.length == 1

  @assets.map.with_index do |asset, i|
    asset.to_iiif_image_record(is_only, i, opts)
  end
end
label() click to toggle source
# File lib/wax_tasks/item.rb, line 70
def label
  label_key = @iiif_config&.dig 'label'
  if @record && label_key
    @record.hash.dig label_key
  else
    @pid
  end
end
record?() click to toggle source
# File lib/wax_tasks/item.rb, line 40
def record?
  @record.is_a? Record
end
simple_derivatives() click to toggle source
# File lib/wax_tasks/item.rb, line 59
def simple_derivatives
  @assets.map(&:simple_derivatives).flatten
end
type() click to toggle source
# File lib/wax_tasks/item.rb, line 28
def type
  Dir.exist?(@path) ? 'dir' : File.extname(@path).downcase
end
valid?() click to toggle source
# File lib/wax_tasks/item.rb, line 34
def valid?
  accepted_image_formats.include? @type or @type == 'dir'
end