Class: WaxTasks::Collection

Inherits:
Object
  • Object
show all
Includes:
Images, Metadata
Defined in:
lib/wax_tasks/collection.rb,
lib/wax_tasks/collection/images.rb,
lib/wax_tasks/collection/metadata.rb

Defined Under Namespace

Modules: Images, Metadata

Constant Summary collapse

IMAGE_DERIVATIVE_DIRECTORY =
'img/derivatives'
DEFAULT_VARIANTS =
{ 'thumbnail' => 250, 'fullwidth' => 1140 }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Images

#add_font_matter_to_json_files, #add_iiif_results_to_records, #iiif_builder, #items_from_imagedata, #pre_process_pdfs, #write_iiif_derivatives, #write_simple_derivatives

Methods included from Metadata

#consolidate_records, #csv_string, #json_string, #records_from_metadata, #records_from_pages, #search_fields=, #update_metadata, #yaml_string

Constructor Details

#initialize(name, config, source, collections_dir, ext) ⇒ Collection

Returns a new instance of Collection.



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/wax_tasks/collection.rb', line 21

def initialize(name, config, source, collections_dir, ext)
  @name                     = name
  @config                   = config
  @page_extension           = ext
  @site_source              = source
  @page_source              = Utils.safe_join source, collections_dir, "_#{@name}"
  @metadata_source          = Utils.safe_join source, '_data', config.dig('metadata', 'source')
  @imagedata_source         = Utils.safe_join source, '_data', config.dig('images', 'source')
  @iiif_derivative_source   = Utils.safe_join source, IMAGE_DERIVATIVE_DIRECTORY, 'iiif'
  @simple_derivative_source = Utils.safe_join source, IMAGE_DERIVATIVE_DIRECTORY, 'simple'
  @search_fields            = %w[pid label thumbnail permalink collection]
  @image_variants           = image_variants
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/wax_tasks/collection.rb', line 9

def config
  @config
end

#extObject (readonly)

Returns the value of attribute ext.



9
10
11
# File 'lib/wax_tasks/collection.rb', line 9

def ext
  @ext
end

#iiif_derivative_sourceObject (readonly)

Returns the value of attribute iiif_derivative_source.



9
10
11
# File 'lib/wax_tasks/collection.rb', line 9

def iiif_derivative_source
  @iiif_derivative_source
end

#imagedata_sourceObject (readonly)

Returns the value of attribute imagedata_source.



9
10
11
# File 'lib/wax_tasks/collection.rb', line 9

def imagedata_source
  @imagedata_source
end

#metadata_sourceObject (readonly)

Returns the value of attribute metadata_source.



9
10
11
# File 'lib/wax_tasks/collection.rb', line 9

def 
  @metadata_source
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/wax_tasks/collection.rb', line 9

def name
  @name
end

#page_sourceObject (readonly)

Returns the value of attribute page_source.



9
10
11
# File 'lib/wax_tasks/collection.rb', line 9

def page_source
  @page_source
end

#search_fieldsObject (readonly)

Returns the value of attribute search_fields.



9
10
11
# File 'lib/wax_tasks/collection.rb', line 9

def search_fields
  @search_fields
end

#simple_derivative_sourceObject (readonly)

Returns the value of attribute simple_derivative_source.



9
10
11
# File 'lib/wax_tasks/collection.rb', line 9

def simple_derivative_source
  @simple_derivative_source
end

Instance Method Details

#clobber_derivativesObject



52
53
54
55
56
57
58
59
# File 'lib/wax_tasks/collection.rb', line 52

def clobber_derivatives
  [@iiif_derivative_source, @simple_derivative_source].each do |dir|
    if Dir.exist? dir
      puts Rainbow("Removing derivatives from #{dir}").cyan
      FileUtils.remove_dir dir, true
    end
  end
end

#clobber_pagesObject



44
45
46
47
48
# File 'lib/wax_tasks/collection.rb', line 44

def clobber_pages
  return unless Dir.exist? @page_source
  puts Rainbow("Removing pages from #{@page_source}").cyan
  FileUtils.remove_dir @page_source, true
end

#image_variantsObject



37
38
39
40
# File 'lib/wax_tasks/collection.rb', line 37

def image_variants
  vars = @config.dig('images', 'variants') || {}
  DEFAULT_VARIANTS.merge vars
end