Class: IiifPrint::Configuration
- Inherits:
-
Object
- Object
- IiifPrint::Configuration
- Defined in:
- lib/iiif_print/configuration.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#additional_tesseract_options ⇒ String
The additional options to pass to the Tesseract configuration.
-
#after_create_fileset_handler ⇒ Object
writeonly
Sets the attribute after_create_fileset_handler.
-
#all_text_generator_function ⇒ Object
This configuration determines where to pull the full text from.
-
#ancestory_identifier_function ⇒ Proc
The function, with arity 1, that receives a work and returns it’s identifier (as a string) for the purposes of object ancestry.
-
#child_work_attributes_function ⇒ Object
Here we allow for customization of the child work attributes rubocop:disable Metrics/MethodLength, Metrics/BlockLength.
- #default_iiif_manifest_version ⇒ Object
-
#excluded_model_name_solr_field_key ⇒ String
A string of a solr field key.
-
#excluded_model_name_solr_field_values ⇒ Array<String>
By default, this uses an array of human readable types ex: [‘Generic Work’, ‘Image’].
-
#iiif_metadata_field_presentation_order ⇒ Array<Symbol>
This is the default sorter for the metadata.
- #ingest_queue_name ⇒ Symbol, Proc
-
#metadata_fields ⇒ Object
private
rubocop:disable Metrics/MethodLength.
-
#ocr_coords_from_json_function ⇒ Object
This is used to determine where to pull the OCR coordinates from.
- #persistence_adapter ⇒ Object
-
#sort_iiif_manifest_canvases_by ⇒ Object
Normally, the canvases are sorted by the ‘ordered_members` association.
-
#unique_child_title_generator_function ⇒ Proc
The function, with keywords (though maybe you’ll want to splat ignore a few), is responsible for generating the child work file title.
-
#uv_base_path ⇒ Object
While we’re at it, we’re going to go ahead and make the base path configurable as well.
-
#uv_config_path ⇒ Object
According to github.com/samvera/hyrax/wiki/Hyrax-Management-Guide#universal-viewer-config the name of the UV config file should be /uv/uv_config.json (with an _) However, in most applications, it is /uv/uv-config.json (with a -).
Instance Method Summary collapse
- #default_persistence_adapter ⇒ Object
- #handle_after_create_fileset(file_set, user) ⇒ Object
-
#questioning_authority_fields ⇒ Object
This is used to explicitly set which fields should be rendered as a Questioning Authority in the UV.
- #questioning_authority_fields=(fields) ⇒ Object
-
#registered_ingest_dirs ⇒ Array<String>
This method wraps Hyrax’s configuration so we can sniff out the correct method to use.
-
#skip_splitting_pdf_files_that_end_with_these_texts ⇒ Object
@return [Array<String>] the file suffixes (e.g. [“.reader.pdf”]) that we will skip.
- #skip_splitting_pdf_files_that_end_with_these_texts=(values) ⇒ Object
Instance Attribute Details
#additional_tesseract_options ⇒ String
The additional options to pass to the Tesseract configuration
171 172 173 |
# File 'lib/iiif_print/configuration.rb', line 171 def || "" end |
#after_create_fileset_handler=(value) ⇒ Object (writeonly)
Sets the attribute after_create_fileset_handler
4 5 6 |
# File 'lib/iiif_print/configuration.rb', line 4 def after_create_fileset_handler=(value) @after_create_fileset_handler = value end |
#all_text_generator_function ⇒ Object
This configuration determines where to pull the full text from. By default, it will pull from the TXT file that is generated by the OCR engine. However, if your application has its own implementation of generating the full text, then you can set your own configuration here.
266 267 268 269 270 |
# File 'lib/iiif_print/configuration.rb', line 266 def all_text_generator_function @all_text_generator_function ||= lambda do |object:| IiifPrint::Data::WorkDerivatives.data(from: object, of_type: 'txt') end end |
#ancestory_identifier_function ⇒ Proc
The function, with arity 1, that receives a work and returns it’s identifier (as a string) for the purposes of object ancestry.
51 52 53 54 55 |
# File 'lib/iiif_print/configuration.rb', line 51 def ancestory_identifier_function # If the work.id is nil, keep it nil. Otherwise cast that id to a string; to deal with the # `Valkyrie::ID`. @ancestory_identifier_function ||= ->(work) { work.id&.to_s } end |
#child_work_attributes_function ⇒ Object
Here we allow for customization of the child work attributes rubocop:disable Metrics/MethodLength, Metrics/BlockLength
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/iiif_print/configuration.rb', line 195 def child_work_attributes_function @child_work_attributes_function ||= lambda do |parent_work:, admin_set_id:| = parent_work. lease = parent_work.lease = {} lease_params = {} visibility_params = {} if = { visibility: 'embargo', visibility_after_embargo: ., visibility_during_embargo: ., embargo_release_date: . } elsif lease lease_params = { visibility: 'lease', visibility_after_lease: lease.visibility_after_lease, visibility_during_lease: lease.visibility_during_lease, lease_release_date: lease.lease_expiration_date } else visibility_params = { visibility: parent_work.visibility.to_s } end params = { admin_set_id: admin_set_id.to_s, creator: parent_work.creator.to_a, rights_statement: parent_work.rights_statement.to_a, is_child: true } params.merge!().merge!(lease_params).merge!(visibility_params) end end |
#default_iiif_manifest_version ⇒ Object
127 128 129 |
# File 'lib/iiif_print/configuration.rb', line 127 def default_iiif_manifest_version @default_iiif_manifest_version.presence || 2 end |
#excluded_model_name_solr_field_key ⇒ String
A string of a solr field key
121 122 123 124 |
# File 'lib/iiif_print/configuration.rb', line 121 def excluded_model_name_solr_field_key return "human_readable_type_sim" unless defined?(@excluded_model_name_solr_field_key) @excluded_model_name_solr_field_key end |
#excluded_model_name_solr_field_values ⇒ Array<String>
By default, this uses an array of human readable types
ex: ['Generic Work', 'Image']
61 62 63 64 |
# File 'lib/iiif_print/configuration.rb', line 61 def excluded_model_name_solr_field_values return @excluded_model_name_solr_field_values unless @excluded_model_name_solr_field_values.nil? @excluded_model_name_solr_field_values = [] end |
#iiif_metadata_field_presentation_order ⇒ Array<Symbol>
This is the default sorter for the metadata. It will sort by the order of the keys specificied. By default, this is turned off as it returns nil. If you want to turn it on, you can set this this to an array of symbols the properties on the work.
280 281 282 |
# File 'lib/iiif_print/configuration.rb', line 280 def || nil end |
#ingest_queue_name ⇒ Symbol, Proc
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/iiif_print/configuration.rb', line 9 def ingest_queue_name return @ingest_queue_name if @ingest_queue_name.present? if defined?(Hyrax) Hyrax.config.ingest_queue_name elsif defined?(Bulkrax) && Bulkrax.config.respond_to?(:ingest_queue_name) Bulkrax.config.ingest_queue_name else :ingest end end |
#metadata_fields ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
To move this to an ‘@api public` state, we need to consider what a proper configuration looks like.
These fields will appear in rendering order.
rubocop:disable Metrics/MethodLength
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/iiif_print/configuration.rb', line 136 def ||= { title: {}, description: {}, collection: {}, abstract: {}, date_modified: {}, creator: { render_as: :faceted }, contributor: { render_as: :faceted }, subject: { render_as: :faceted }, publisher: { render_as: :faceted }, language: { render_as: :faceted }, identifier: { render_as: :linked }, keyword: { render_as: :faceted }, date_created: { render_as: :linked }, based_near_label: {}, related_url: { render_as: :external_link }, resource_type: { render_as: :faceted }, source: {}, extent: {}, rights_statement: { render_as: :rights_statement }, rights_notes: {}, access_right: {}, license: { render_as: :license }, searchable_text: {} } end |
#ocr_coords_from_json_function ⇒ Object
This is used to determine where to pull the OCR coordinates from. By default, it will pull from the JSON file that is generated by the OCR engine. However, if you have a different source, you can set this configuration. Current implementation has access to the ‘file_set_id“ and the `document` [SolrDocument].
254 255 256 257 258 |
# File 'lib/iiif_print/configuration.rb', line 254 def ocr_coords_from_json_function @ocr_coords_from_json_function ||= lambda do |file_set_id:, **| IiifPrint::Data::WorkDerivatives.data(from: file_set_id, of_type: 'json') end end |
#persistence_adapter ⇒ Object
21 22 23 |
# File 'lib/iiif_print/configuration.rb', line 21 def persistence_adapter @persistence_adapter || default_persistence_adapter end |
#sort_iiif_manifest_canvases_by ⇒ Object
Normally, the canvases are sorted by the ‘ordered_members` association. However, if you want it to be sorted by another property, you can set this configuration. Change `nil` to something like `:title` or `:identifier`.
Should you want to sort by the filename of the image, you set ‘nil` to `:label`. This looks at the canvas label, which is typically set to the filename of the image.
242 243 244 |
# File 'lib/iiif_print/configuration.rb', line 242 def sort_iiif_manifest_canvases_by @sort_iiif_manifest_canvases_by || nil end |
#unique_child_title_generator_function ⇒ Proc
The function, with keywords (though maybe you’ll want to splat ignore a few), is responsible for generating the child work file title. of object ancestry.
The keyword parameters that will be passed to this function are:
:original_pdf_path - The fully qualified pathname to the original PDF from which the images
were split.
:image_path - The fully qualified pathname for an image of the single page from the PDF. :parent_work - The object in which we’re “attaching” the image. :page_number - The image is of the N-th page_number of the original PDF :page_padding - A helper number that indicates the number of significant digits of pages
(e.g. 150 pages would have a padding of 3).
rubocop:disable Lint/UnusedBlockArgument
95 96 97 98 99 100 101 102 |
# File 'lib/iiif_print/configuration.rb', line 95 def unique_child_title_generator_function @unique_child_title_generator_function ||= lambda { |original_pdf_path:, image_path:, parent_work:, page_number:, page_padding:| identifier = parent_work.id filename = File.basename(original_pdf_path) page_suffix = "Page #{(page_number.to_i + 1).to_s.rjust(page_padding.to_i, '0')}" "#{identifier} - #{filename} #{page_suffix}" } end |
#uv_base_path ⇒ Object
While we’re at it, we’re going to go ahead and make the base path configurable as well
187 188 189 |
# File 'lib/iiif_print/configuration.rb', line 187 def uv_base_path @uv_base_path || "/uv/uv.html" end |
#uv_config_path ⇒ Object
According to github.com/samvera/hyrax/wiki/Hyrax-Management-Guide#universal-viewer-config the name of the UV config file should be /uv/uv_config.json (with an _) However, in most applications, it is /uv/uv-config.json (with a -)
180 181 182 |
# File 'lib/iiif_print/configuration.rb', line 180 def uv_config_path @uv_config_path || "/uv/uv-config.json" end |
Instance Method Details
#default_persistence_adapter ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/iiif_print/configuration.rb', line 25 def default_persistence_adapter # There's probably some configuration of Hyrax we could use to better refine this; but it's # likely a reasonable guess. The main goal is to not break existing implementations and # maintain an upgrade path. if Gem::Version.new(Hyrax::VERSION) >= Gem::Version.new('6.0.0') IiifPrint::PersistenceLayer::ValkyrieAdapter else IiifPrint::PersistenceLayer::ActiveFedoraAdapter end end |
#handle_after_create_fileset(file_set, user) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/iiif_print/configuration.rb', line 38 def handle_after_create_fileset(file_set, user) if defined? @after_create_fileset_handler @after_create_fileset_handler.call(file_set, user) else IiifPrint::Data.handle_after_create_fileset(file_set, user) end end |
#questioning_authority_fields ⇒ Object
This is used to explicitly set which fields should be rendered as a Questioning Authority in the UV. By default, we render ‘rights_statement` and `license` as QA fields.
291 292 293 |
# File 'lib/iiif_print/configuration.rb', line 291 def ||= ['rights_statement', 'license'] end |
#questioning_authority_fields=(fields) ⇒ Object
284 285 286 |
# File 'lib/iiif_print/configuration.rb', line 284 def (fields) = Array.wrap(fields).map(&:to_s) end |
#registered_ingest_dirs ⇒ Array<String>
This method wraps Hyrax’s configuration so we can sniff out the correct method to use. The Hyrax::Configuration#whitelisted_ingest_dirs is deprecated in favor of Hyrax::Configuration#registered_ingest_dirs.
110 111 112 113 114 115 116 |
# File 'lib/iiif_print/configuration.rb', line 110 def registered_ingest_dirs if Hyrax.config.respond_to?(:registered_ingest_dirs) Hyrax.config.registered_ingest_dirs else Hyrax.config.whitelisted_ingest_dirs end end |
#skip_splitting_pdf_files_that_end_with_these_texts ⇒ Object
@return [Array<String>] the file suffixes (e.g. [“.reader.pdf”]) that we will skip. Per
the implementation of {.split_for_path_suffix?}, these values are cast to
downcase.
74 75 76 |
# File 'lib/iiif_print/configuration.rb', line 74 def skip_splitting_pdf_files_that_end_with_these_texts @skip_splitting_pdf_files_that_end_with_these_texts || [] end |
#skip_splitting_pdf_files_that_end_with_these_texts=(values) ⇒ Object
66 67 68 |
# File 'lib/iiif_print/configuration.rb', line 66 def skip_splitting_pdf_files_that_end_with_these_texts=(values) @skip_splitting_pdf_files_that_end_with_these_texts = Array.wrap(values).map(&:downcase) end |