Class: WaxIiif::Builder
- Inherits:
-
Object
- Object
- WaxIiif::Builder
- Includes:
- Utilities::Helpers
- Defined in:
- lib/wax_iiif/builder.rb
Overview
Builder class
Constant Summary collapse
- HEADER_VAL =
'filename'.freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#manifests ⇒ Array<Hash>
The manifest hashes for this configuration.
Instance Method Summary collapse
-
#create_build_directories ⇒ Void
Creates the required directories for exporting to the file system.
- #generate_collection ⇒ Object
-
#initialize(config = {}) ⇒ Void
constructor
Initialize the builder.
-
#load(data) ⇒ Void
Load data into the IIIF builder.
-
#load_csv(csv_path) ⇒ Void
Load data into the IIIF server from a CSV.
-
#process_data(thread_count: Parallel.processor_count) ⇒ Void
Take the loaded data and generate all the files.
Methods included from Utilities::Helpers
#escape_yaml, #generate_build_location, #generate_id, #generate_image_location, #get_data_path, #save_to_disk
Constructor Details
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
26 27 28 |
# File 'lib/wax_iiif/builder.rb', line 26 def config @config end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
17 18 19 |
# File 'lib/wax_iiif/builder.rb', line 17 def data @data end |
#manifests ⇒ Array<Hash>
Returns The manifest hashes for this configuration.
22 23 24 |
# File 'lib/wax_iiif/builder.rb', line 22 def manifests @manifests end |
Instance Method Details
#create_build_directories ⇒ Void
Creates the required directories for exporting to the file system.
110 111 112 113 114 115 |
# File 'lib/wax_iiif/builder.rb', line 110 def create_build_directories root_dir = generate_build_location('') Dir.mkdir root_dir unless Dir.exist?(root_dir) img_dir = generate_image_location('').split('/')[0...-1].join('/') Dir.mkdir img_dir unless Dir.exist?(img_dir) end |
#generate_collection ⇒ Object
101 102 103 104 105 |
# File 'lib/wax_iiif/builder.rb', line 101 def generate_collection collection = Collection.new(@config) manifests.each { |m| collection.add_manifest(m) } collection.save end |
#load(data) ⇒ Void
Load data into the IIIF builder.
This will load the data, perform some basic verifications on it, and sort it into proper order.
52 53 54 55 56 57 58 59 |
# File 'lib/wax_iiif/builder.rb', line 52 def load(data) @data = [data].flatten # handle hashes and arrays of hashes # validate @data.each do |image_record| raise WaxIiif::Error::InvalidImageData, "Image record #{image_record.inspect} is not an ImageRecord" unless image_record.is_a? ImageRecord raise WaxIiif::Error::InvalidImageData, "Image record #{image_record.inspect} does not have an ID" if image_record.id.nil? end end |
#load_csv(csv_path) ⇒ Void
Fix this to use the correct data format!
Load data into the IIIF server from a CSV
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/wax_iiif/builder.rb', line 124 def load_csv(csv_path) raise Error::InvalidCSV unless File.exist? csv_path begin vals = CSV.read(csv_path) rescue CSV::MalformedCSVError raise Error::InvalidCSV end raise Error::BlankCSV if vals.length.zero? raise Error::InvalidCSV if vals[0].length != 3 # remove optional header vals.shift if vals[0][0] == HEADER_VAL @data = vals.collect { |d| { 'image_path' => d[0], 'id' => d[1], 'label' => d[2] } } end |
#process_data(thread_count: Parallel.processor_count) ⇒ Void
Take the loaded data and generate all the files.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/wax_iiif/builder.rb', line 68 def process_data(thread_count: Parallel.processor_count) puts Rainbow("Running on #{thread_count} threads.").blue return nil if @data.nil? # do nothing without data. @manifests = [] data = @data.group_by(&:manifest_id) = ProgressBar.new(data.length) .write data.each do |key, value| manifest_id = key image_records = value resources = process_image_records(image_records, thread_count: thread_count) # Generate the manifest if manifest_id.to_s.empty? resources.each do |_key, val| manifests.push generate_manifest(val, @config) end else manifests.push generate_manifest(image_records, @config) end .increment! .write end generate_collection end |