Class: WaxTasks::Item
- Inherits:
-
Object
- Object
- WaxTasks::Item
- Defined in:
- lib/wax_tasks/item.rb
Instance Attribute Summary collapse
-
#iiif_config ⇒ Object
Returns the value of attribute iiif_config.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#record ⇒ Object
Returns the value of attribute record.
Instance Method Summary collapse
- #accepted_image_formats ⇒ Object
- #assets ⇒ Object
- #attribution ⇒ Object
- #base_opts ⇒ Object
- #description ⇒ Object
- #iiif_image_records ⇒ Object
-
#initialize(path, variants) ⇒ Item
constructor
A new instance of Item.
- #label ⇒ Object
- #logo ⇒ Object
- #record? ⇒ Boolean
- #simple_derivatives ⇒ Object
- #type ⇒ Object
- #valid? ⇒ Boolean
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_config ⇒ Object
Returns the value of attribute iiif_config.
6 7 8 |
# File 'lib/wax_tasks/item.rb', line 6 def iiif_config @iiif_config end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
7 8 9 |
# File 'lib/wax_tasks/item.rb', line 7 def pid @pid end |
#record ⇒ Object
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_formats ⇒ Object
22 23 24 |
# File 'lib/wax_tasks/item.rb', line 22 def accepted_image_formats %w[.png .jpg .jpeg .tiff .tif] end |
#assets ⇒ Object
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 |
#attribution ⇒ Object
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_opts ⇒ Object
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] = logo if logo opts[:description] = description.to_s if description opts[:attribution] = attribution.to_s if attribution opts end |
#description ⇒ Object
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_records ⇒ Object
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 |
#label ⇒ Object
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 |
#logo ⇒ Object
65 66 67 68 |
# File 'lib/wax_tasks/item.rb', line 65 def logo logo_uri = @iiif_config&.dig 'logo' "{{ '#{logo_uri}' | absolute_url }}" if logo_uri end |
#record? ⇒ Boolean
40 41 42 |
# File 'lib/wax_tasks/item.rb', line 40 def record? @record.is_a? Record end |
#simple_derivatives ⇒ Object
59 60 61 |
# File 'lib/wax_tasks/item.rb', line 59 def simple_derivatives @assets.map(&:simple_derivatives).flatten end |
#type ⇒ Object
28 29 30 |
# File 'lib/wax_tasks/item.rb', line 28 def type Dir.exist?(@path) ? 'dir' : File.extname(@path).downcase end |
#valid? ⇒ Boolean
34 35 36 |
# File 'lib/wax_tasks/item.rb', line 34 def valid? accepted_image_formats.include? @type or @type == 'dir' end |