Class: Aperitiiif::Item

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#assetsObject (readonly)

Returns the value of attribute assets.



15
16
17
# File 'lib/aperitiiif/item.rb', line 15

def assets
  @assets
end

#idObject (readonly)

Returns the value of attribute id.



15
16
17
# File 'lib/aperitiiif/item.rb', line 15

def id
  @id
end

#recordObject



31
32
33
# File 'lib/aperitiiif/item.rb', line 31

def record
  @record || default_record
end

Instance Method Details

#build_manifestObject



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_recordObject



35
36
37
# File 'lib/aperitiiif/item.rb', line 35

def default_record
  Record.new({ 'id' => id }, @config.records_defaults)
end

#labelObject



43
44
45
# File 'lib/aperitiiif/item.rb', line 43

def label
  record.label
end

#manifestObject



39
40
41
# File 'lib/aperitiiif/item.rb', line 39

def manifest
  @manifest ||= build_manifest
end

#manifest_fileObject



81
82
83
# File 'lib/aperitiiif/item.rb', line 81

def manifest_file
  "#{@config.presentation_build_dir}/#{@config.namespace}/#{id}/manifest.json"
end

#manifest_urlObject



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

Returns:

  • (Boolean)


85
86
87
# File 'lib/aperitiiif/item.rb', line 85

def manifest_written?
  File.file? manifest_file
end

#seedObject

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.,
    'description' => record.description,
    'source' => record.source,
    'metadata' => record.
  }.delete_if { |_key, val| val.blank? }
end

#thumbnail_urlObject



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_hashObject



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_configObject

Raises:



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_urlObject



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_jsonObject



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