Class: Aperitiiif::Item
- Inherits:
-
Object
- Object
- Aperitiiif::Item
- Defined in:
- lib/aperitiiif/item.rb
Overview
to do has smell :reek:InstanceVariableAssumption has smell :reek:TooManyInstanceVariables has smell :reek:TooManyMethods
Instance Attribute Summary collapse
-
#assets ⇒ Object
readonly
Returns the value of attribute assets.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
- #record ⇒ Object
Instance Method Summary collapse
- #build_manifest ⇒ Object
- #default_record ⇒ Object
-
#initialize(id, assets, config) ⇒ Item
constructor
A new instance of Item.
- #label ⇒ Object
- #manifest ⇒ Object
- #manifest_file ⇒ Object
- #manifest_url ⇒ Object
- #manifest_written? ⇒ Boolean
-
#seed ⇒ Object
has smell :reek: TooManyStatements.
- #thumbnail_url ⇒ Object
- #to_hash ⇒ Object
- #validate_config ⇒ Object
- #viewpoint_url ⇒ Object
- #write_presentation_json ⇒ Object
Constructor Details
#initialize(id, assets, config) ⇒ Item
Returns a new instance of Item.
17 18 19 20 21 22 23 |
# File 'lib/aperitiiif/item.rb', line 17 def initialize(id, assets, config) @id = id @config = config @assets = assets validate_config end |
Instance Attribute Details
#assets ⇒ Object (readonly)
Returns the value of attribute assets.
15 16 17 |
# File 'lib/aperitiiif/item.rb', line 15 def assets @assets end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
15 16 17 |
# File 'lib/aperitiiif/item.rb', line 15 def id @id end |
#record ⇒ Object
31 32 33 |
# File 'lib/aperitiiif/item.rb', line 31 def record @record || default_record end |
Instance Method Details
#build_manifest ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/aperitiiif/item.rb', line 73 def build_manifest manifest = IIIF::Presentation::Manifest.new seed sequence = IIIF::Presentation::Sequence.new sequence.canvases = assets.map(&:canvas) manifest.sequences << sequence manifest end |
#default_record ⇒ Object
35 36 37 |
# File 'lib/aperitiiif/item.rb', line 35 def default_record Record.new({ 'id' => id }, @config.records_defaults) end |
#label ⇒ Object
43 44 45 |
# File 'lib/aperitiiif/item.rb', line 43 def label record.label end |
#manifest ⇒ Object
39 40 41 |
# File 'lib/aperitiiif/item.rb', line 39 def manifest @manifest ||= build_manifest end |
#manifest_file ⇒ Object
81 82 83 |
# File 'lib/aperitiiif/item.rb', line 81 def manifest_file "#{@config.presentation_build_dir}/#{@config.namespace}/#{id}/manifest.json" end |
#manifest_url ⇒ Object
47 48 49 |
# File 'lib/aperitiiif/item.rb', line 47 def manifest_url "#{@config.presentation_api_url}/#{@config.namespace}/#{@id}/manifest.json" end |
#manifest_written? ⇒ Boolean
85 86 87 |
# File 'lib/aperitiiif/item.rb', line 85 def manifest_written? File.file? manifest_file end |
#seed ⇒ Object
has smell :reek: TooManyStatements
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/aperitiiif/item.rb', line 62 def seed { '@id' => manifest_url, 'label' => label, 'logo' => record.logo, 'description' => record.description, 'source' => record.source, 'metadata' => record. }.delete_if { |_key, val| val.blank? } end |
#thumbnail_url ⇒ Object
51 52 53 54 55 |
# File 'lib/aperitiiif/item.rb', line 51 def thumbnail_url return '' if assets.empty? assets.first.thumbnail_url end |
#to_hash ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'lib/aperitiiif/item.rb', line 93 def to_hash { 'id' => id, 'label' => label, 'manifest_url' => manifest_url, 'thumbnail_url' => thumbnail_url, 'viewpoint_url' => viewpoint_url } end |
#validate_config ⇒ Object
25 26 27 28 29 |
# File 'lib/aperitiiif/item.rb', line 25 def validate_config raise Aperitiiif::Error, "No value found for 'namespace'. Check your config?" if @config.namespace.empty? raise Aperitiiif::Error, "No value found for 'presentation_api_url'. Check your config?" if @config.presentation_api_url.empty? raise Aperitiiif::Error, "No value found for 'presentation_build_dir'. Check your config?" if @config.presentation_build_dir.empty? end |
#viewpoint_url ⇒ Object
57 58 59 |
# File 'lib/aperitiiif/item.rb', line 57 def viewpoint_url "https://dss.hosting.nyu.edu/viewpoint/mirador/#manifests[]=#{CGI.escape manifest_url}&theme=dark" end |
#write_presentation_json ⇒ Object
89 90 91 |
# File 'lib/aperitiiif/item.rb', line 89 def write_presentation_json Aperitiiif::Utils.mkfile_p manifest_file, manifest.to_json(pretty: true) end |