Class: Aperitiiif::Batch

Inherits:
Object
  • Object
show all
Includes:
Assets, Items, Linters, Records
Defined in:
lib/aperitiiif/batch.rb

Overview

TO DO COMMENT

Constant Summary collapse

DEFAULT_CONFIG_FILE =
'./config.yml'

Instance Method Summary collapse

Methods included from Records

#find_record, #load_records!, #records, #records_file_configured?, #records_file_exists?, #records_from_file

Methods included from Linters

#lint, #linters, #report_failures, #warn_duplicate_image_names, #warn_duplicate_record_ids, #warn_missing_labels, #warn_nil_record_items, #warn_stray_files

Methods included from Items

#items, #items=, #items_from_assets

Methods included from Assets

#asset_map, #assets, #child_assets, #map_to_assets

Constructor Details

#initializeBatch

Returns a new instance of Batch.



22
# File 'lib/aperitiiif/batch.rb', line 22

def initialize; end

Instance Method Details

#configObject



26
27
28
# File 'lib/aperitiiif/batch.rb', line 26

def config
  @config ||= load_config_file
end

#iiif_collectionObject



70
71
72
73
74
# File 'lib/aperitiiif/batch.rb', line 70

def iiif_collection
  collection = IIIF::Presentation::Collection.new seed
  collection.manifests = items.map(&:manifest)
  collection
end

#iiif_collection_fileObject



76
# File 'lib/aperitiiif/batch.rb', line 76

def iiif_collection_file      = "#{config.presentation_build_dir}/#{config.namespace}/collection.json"

#iiif_collection_urlObject



77
# File 'lib/aperitiiif/batch.rb', line 77

def iiif_collection_url       = "#{config.presentation_api_url}/#{config.namespace}/collection.json"

#iiif_collection_written?Boolean

Returns:

  • (Boolean)


78
# File 'lib/aperitiiif/batch.rb', line 78

def iiif_collection_written?  = File.file? iiif_collection_file

#load_config_file(file = DEFAULT_CONFIG_FILE) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/aperitiiif/batch.rb', line 30

def load_config_file(file = DEFAULT_CONFIG_FILE)
  @config = Config.new SafeYAML.load_file file
rescue StandardError
  raise Aperitiiif::Error, "Cannot find file #{file}" unless File.file?(file)

  raise Aperitiiif::Error, "Cannot read file #{file}. Is it valid yaml?"
end

#load_config_hash(hash) ⇒ Object



38
39
40
# File 'lib/aperitiiif/batch.rb', line 38

def load_config_hash(hash)
  @config = Config.new hash
end

#reset(dir = config.build_dir) ⇒ Object



42
43
44
45
46
# File 'lib/aperitiiif/batch.rb', line 42

def reset(dir = config.build_dir)
  puts 'Resetting build...'.colorize(:cyan)
  FileUtils.rm_rf dir
  puts 'Done ✓'.colorize(:green)
end

#seedObject



61
62
63
64
65
66
67
68
# File 'lib/aperitiiif/batch.rb', line 61

def seed
  {
    '@id' => iiif_collection_url,
    'label' => config.label,
    'description' => config.batch_description,
    'attribution' => config.batch_attribution
  }.delete_if { |_key, val| val.blank? }
end

#write_iiif_collection_jsonObject



80
81
82
# File 'lib/aperitiiif/batch.rb', line 80

def write_iiif_collection_json
  Aperitiiif::Utils.mkfile_p iiif_collection_file, iiif_collection.to_json(pretty: true)
end

#write_presentation_json(items = self.items) ⇒ Object

has smell :reek:TooManyStatements



54
55
56
57
58
59
# File 'lib/aperitiiif/batch.rb', line 54

def write_presentation_json(items = self.items)
  msg = 'Writing IIIF Presentation JSON'.colorize(:cyan)
  load_records!
  Parallel.map(items, in_threads: 4, progress: { format: "#{msg}: %c/%u | %P%" }, &:write_presentation_json)
  write_iiif_collection_json
end

#write_target_assets(assets = self.assets) ⇒ Object



48
49
50
51
# File 'lib/aperitiiif/batch.rb', line 48

def write_target_assets(assets = self.assets)
  msg = 'Writing target image TIFs'.colorize(:cyan)
  Parallel.map(assets, in_threads: 4, progress: { format: "#{msg}: %c/%u | %P%" }, &:write_to_target)
end