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
-
#disk_limit ⇒ Object
Example settings in the initializer: config.memory_limit = “512MiB” # Limit for memory usage config.map_limit = “1GiB” # Limit for map usage config.disk_limit = “20KP” # Limit for disk usage.
-
#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’].
- #external_iiif_url ⇒ Object
-
#iiif_metadata_field_presentation_order ⇒ Array<Symbol>
This is the default sorter for the metadata.
- #iiif_s3_folder_prefix ⇒ Object
- #ingest_queue_name ⇒ Symbol, Proc
-
#map_limit ⇒ Object
Example settings in the initializer: config.memory_limit = “512MiB” # Limit for memory usage config.map_limit = “1GiB” # Limit for map usage config.disk_limit = “20KP” # Limit for disk usage.
-
#memory_limit ⇒ Object
Example settings in the initializer: config.memory_limit = “512MiB” # Limit for memory usage config.map_limit = “1GiB” # Limit for map usage config.disk_limit = “20KP” # Limit for disk usage.
-
#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
187 188 189 |
# File 'lib/iiif_print/configuration.rb', line 187 def @additional_tesseract_options || "" 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.
282 283 284 285 286 |
# File 'lib/iiif_print/configuration.rb', line 282 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.
57 58 59 60 61 |
# File 'lib/iiif_print/configuration.rb', line 57 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
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/iiif_print/configuration.rb', line 211 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
133 134 135 |
# File 'lib/iiif_print/configuration.rb', line 133 def default_iiif_manifest_version @default_iiif_manifest_version.presence || 2 end |
#disk_limit ⇒ Object
Example settings in the initializer: config.memory_limit = “512MiB” # Limit for memory usage config.map_limit = “1GiB” # Limit for map usage config.disk_limit = “20KP” # Limit for disk usage
12 13 14 |
# File 'lib/iiif_print/configuration.rb', line 12 def disk_limit @disk_limit end |
#excluded_model_name_solr_field_key ⇒ String
A string of a solr field key
127 128 129 130 |
# File 'lib/iiif_print/configuration.rb', line 127 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']
67 68 69 70 |
# File 'lib/iiif_print/configuration.rb', line 67 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 |
#external_iiif_url ⇒ Object
138 139 140 |
# File 'lib/iiif_print/configuration.rb', line 138 def external_iiif_url @external_iiif_url || ENV['EXTERNAL_IIIF_URL'] 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.
296 297 298 |
# File 'lib/iiif_print/configuration.rb', line 296 def @iiif_metadata_field_presentation_order || nil end |
#iiif_s3_folder_prefix ⇒ Object
143 144 145 |
# File 'lib/iiif_print/configuration.rb', line 143 def iiif_s3_folder_prefix @iiif_s3_folder_prefix || ENV['IIIF_S3_FOLDER_PREFIX'] end |
#ingest_queue_name ⇒ Symbol, Proc
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/iiif_print/configuration.rb', line 15 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 |
#map_limit ⇒ Object
Example settings in the initializer: config.memory_limit = “512MiB” # Limit for memory usage config.map_limit = “1GiB” # Limit for map usage config.disk_limit = “20KP” # Limit for disk usage
12 13 14 |
# File 'lib/iiif_print/configuration.rb', line 12 def map_limit @map_limit end |
#memory_limit ⇒ Object
Example settings in the initializer: config.memory_limit = “512MiB” # Limit for memory usage config.map_limit = “1GiB” # Limit for map usage config.disk_limit = “20KP” # Limit for disk usage
12 13 14 |
# File 'lib/iiif_print/configuration.rb', line 12 def memory_limit @memory_limit 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
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/iiif_print/configuration.rb', line 152 def @metadata_fields ||= { 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].
270 271 272 273 274 |
# File 'lib/iiif_print/configuration.rb', line 270 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
27 28 29 |
# File 'lib/iiif_print/configuration.rb', line 27 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.
258 259 260 |
# File 'lib/iiif_print/configuration.rb', line 258 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
101 102 103 104 105 106 107 108 |
# File 'lib/iiif_print/configuration.rb', line 101 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
203 204 205 |
# File 'lib/iiif_print/configuration.rb', line 203 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 -)
196 197 198 |
# File 'lib/iiif_print/configuration.rb', line 196 def uv_config_path @uv_config_path || "/uv/uv-config.json" end |
Instance Method Details
#default_persistence_adapter ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/iiif_print/configuration.rb', line 31 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
44 45 46 47 48 49 50 |
# File 'lib/iiif_print/configuration.rb', line 44 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.
307 308 309 |
# File 'lib/iiif_print/configuration.rb', line 307 def @questioning_authority_fields ||= ['rights_statement', 'license'] end |
#questioning_authority_fields=(fields) ⇒ Object
300 301 302 |
# File 'lib/iiif_print/configuration.rb', line 300 def (fields) @questioning_authority_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.
116 117 118 119 120 121 122 |
# File 'lib/iiif_print/configuration.rb', line 116 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.
80 81 82 |
# File 'lib/iiif_print/configuration.rb', line 80 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
72 73 74 |
# File 'lib/iiif_print/configuration.rb', line 72 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 |