Class: WaxTasks::Item

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, variants) ⇒ Item

Returns a new instance of Item.



12
13
14
15
16
17
18
# 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

Instance Attribute Details

#iiif_configObject

Returns the value of attribute iiif_config.



6
7
8
# File 'lib/wax_tasks/item.rb', line 6

def iiif_config
  @iiif_config
end

#pidObject (readonly)

Returns the value of attribute pid.



7
8
9
# File 'lib/wax_tasks/item.rb', line 7

def pid
  @pid
end

#recordObject

Returns the value of attribute record.



6
7
8
# File 'lib/wax_tasks/item.rb', line 6

def record
  @record
end

Instance Method Details

#accepted_image_formatsObject



22
23
24
# File 'lib/wax_tasks/item.rb', line 22

def accepted_image_formats
  %w[.png .jpg .jpeg .tiff .tif]
end

#assetsObject



46
47
48
49
50
51
52
53
54
55
# 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

#attributionObject



88
89
90
91
# 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_optsObject



106
107
108
109
110
111
112
113
114
# File 'lib/wax_tasks/item.rb', line 106

def base_opts
  opts = { label: label }
  return opts unless @iiif_config

  opts[:logo]        =  if 
  opts[:description] = description.to_s if description
  opts[:attribution] = attribution.to_s if attribution
  opts
end

#descriptionObject



81
82
83
84
# 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_recordsObject



95
96
97
98
99
100
101
102
# 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

#labelObject



70
71
72
73
74
75
76
77
# 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

#logoObject



65
66
67
68
# File 'lib/wax_tasks/item.rb', line 65

def 
  logo_uri = @iiif_config&.dig 'logo'
  "{{ '#{logo_uri}' | absolute_url }}" if logo_uri
end

#record?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/wax_tasks/item.rb', line 40

def record?
  @record.is_a? Record
end

#simple_derivativesObject



59
60
61
# File 'lib/wax_tasks/item.rb', line 59

def simple_derivatives
  @assets.map(&:simple_derivatives).flatten
end

#typeObject



28
29
30
# File 'lib/wax_tasks/item.rb', line 28

def type
  Dir.exist?(@path) ? 'dir' : File.extname(@path).downcase
end

#valid?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/wax_tasks/item.rb', line 34

def valid?
  accepted_image_formats.include? @type or @type == 'dir'
end