assembly-objectfile 1.12.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +14 -0
  3. data/.github/pull_request_template.md +1 -1
  4. data/.gitignore +0 -1
  5. data/.rubocop.yml +117 -12
  6. data/.rubocop_todo.yml +3 -109
  7. data/Gemfile.lock +97 -0
  8. data/README.md +7 -7
  9. data/assembly-objectfile.gemspec +8 -11
  10. data/config/boot.rb +0 -1
  11. data/lib/{assembly-objectfile → assembly/object_file}/version.rb +2 -2
  12. data/lib/{assembly-objectfile/object_fileable.rb → assembly/object_file.rb} +109 -104
  13. data/lib/assembly-objectfile.rb +12 -15
  14. data/spec/assembly/object_file_spec.rb +451 -0
  15. data/spec/spec_helper.rb +2 -31
  16. data/spec/test_data/empty.txt +0 -0
  17. metadata +23 -156
  18. data/.travis.yml +0 -20
  19. data/lib/assembly-objectfile/content_metadata/config.rb +0 -26
  20. data/lib/assembly-objectfile/content_metadata/file.rb +0 -63
  21. data/lib/assembly-objectfile/content_metadata/file_set.rb +0 -73
  22. data/lib/assembly-objectfile/content_metadata/file_set_builder.rb +0 -65
  23. data/lib/assembly-objectfile/content_metadata/nokogiri_builder.rb +0 -57
  24. data/lib/assembly-objectfile/content_metadata.rb +0 -117
  25. data/lib/assembly-objectfile/object_file.rb +0 -29
  26. data/profiles/AdobeRGB1998.icc +0 -0
  27. data/profiles/DotGain20.icc +0 -0
  28. data/profiles/sRGBIEC6196621.icc +0 -0
  29. data/spec/content_metadata_spec.rb +0 -809
  30. data/spec/object_file_spec.rb +0 -217
  31. data/spec/test_data/input/oo000oo0001/00/oo000oo0001_00_001.tif +0 -0
  32. data/spec/test_data/input/oo000oo0001/00/oo000oo0001_00_002.tif +0 -0
  33. data/spec/test_data/input/oo000oo0001/05/oo000oo0001_05_001.jp2 +0 -0
  34. data/spec/test_data/input/oo000oo0001/05/oo000oo0001_05_002.jp2 +0 -0
  35. data/spec/test_data/input/oo000oo0001/15/oo000oo0001_15_001.pdf +0 -1
  36. data/spec/test_data/input/oo000oo0001/15/oo000oo0001_15_002.pdf +0 -1
  37. data/spec/test_data/input/oo000oo0001/31/oo000oo0001_31_001.pdf +0 -1
  38. data/spec/test_data/input/oo000oo0001/50/oo000oo0001_50_001.tif +0 -0
  39. data/spec/test_data/input/oo000oo0001/oo000oo0001_book.pdf +0 -1
  40. data/spec/test_data/input/res1_image1.jp2 +0 -0
  41. data/spec/test_data/input/res1_image2.jp2 +0 -0
  42. data/spec/test_data/input/res1_image2.tif +0 -0
  43. data/spec/test_data/input/res1_teifile.txt +0 -1
  44. data/spec/test_data/input/res2_image1.jp2 +0 -0
  45. data/spec/test_data/input/res2_image1.tif +0 -0
  46. data/spec/test_data/input/res2_image2.jp2 +0 -0
  47. data/spec/test_data/input/res2_image2.tif +0 -0
  48. data/spec/test_data/input/res2_teifile.txt +0 -1
  49. data/spec/test_data/input/res2_textfile.txt +0 -1
  50. data/spec/test_data/input/res3_image1.jp2 +0 -0
  51. data/spec/test_data/input/res3_image1.tif +0 -0
  52. data/spec/test_data/input/res3_teifile.txt +0 -1
  53. data/spec/test_data/input/test.pdf +0 -1
  54. data/spec/test_data/input/test.svg +0 -2
  55. data/spec/test_data/input/test2.jp2 +0 -0
  56. data/spec/test_data/input/test2.tif +0 -0
@@ -1,117 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'nokogiri'
4
- require 'deprecation'
5
- require 'active_support'
6
- require 'assembly-objectfile/content_metadata/file'
7
- require 'assembly-objectfile/content_metadata/file_set'
8
- require 'assembly-objectfile/content_metadata/file_set_builder'
9
- require 'assembly-objectfile/content_metadata/config'
10
- require 'assembly-objectfile/content_metadata/nokogiri_builder'
11
-
12
- module Assembly
13
- SPECIAL_DPG_FOLDERS = %w[31 44 50].freeze # these special dpg folders will force any files contained in them into their own resources, regardless of filenaming convention
14
- # these are used when :bundle=>:dpg only
15
-
16
- DEPRECATED_STYLES = %i[book_with_pdf book_as_image].freeze
17
- VALID_STYLES = %i[simple_image simple_book file map document 3d webarchive-seed].freeze
18
-
19
- # This class generates content metadata for image files
20
- class ContentMetadata
21
- # Generates image content XML metadata for a repository object.
22
- # This method only produces content metadata for images
23
- # and does not depend on a specific folder structure. Note that it is class level method.
24
- #
25
- # @param [Hash] params a hash containg parameters needed to produce content metadata
26
- # :druid = required - a string of druid of the repository object's druid id (with or without 'druid:' prefix)
27
- # :objects = required - an array of Assembly::ObjectFile objects containing the list of files to add to content metadata
28
- # NOTE: if you set the :bundle option to :prebundled, you will need to pass in an array of arrays, and not a flat array, as noted below
29
- # :style = optional - a symbol containing the style of metadata to create, allowed values are
30
- # :simple_image (default), contentMetadata type="image", resource type="image"
31
- # :file, contentMetadata type="file", resource type="file"
32
- # :simple_book, contentMetadata type="book", resource type="page", but any resource which has file(s) other than an image, and also contains no images at all, will be resource type="object"
33
- # :book_with_pdf, contentMetadata type="book", resource type="page", but any resource which has any file(s) other than an image will be resource type="object" - NOTE: THIS IS DEPRECATED
34
- # :book_as_image, as simple_book, but with contentMetadata type="book", resource type="image" (same rule applies for resources with non images) - NOTE: THIS IS DEPRECATED
35
- # :map, like simple_image, but with contentMetadata type="map", resource type="image"
36
- # :3d, contentMetadata type="3d", ".obj" and other configured 3d extension files go into resource_type="3d", everything else into resource_type="file"
37
- # :webarchive-seed, contentMetadata type="webarchive-seed", resource type="image"
38
- # :bundle = optional - a symbol containing the method of bundling files into resources, allowed values are
39
- # :default = all files get their own resources (default)
40
- # :filename = files with the same filename but different extensions get bundled together in a single resource
41
- # :dpg = files representing the same image but of different mimetype that use the SULAIR DPG filenaming standard (00 vs 05) get bundled together in a single resource
42
- # :prebundlded = this option requires you to prebundled the files passed in as an array of arrays, indicating how files are bundlded into resources; this is the most flexible option since it gives you full control
43
- # :add_exif = optional - a boolean to indicate if exif data should be added (mimetype, filesize, image height/width, etc.) to each file, defaults to false and is not required if project goes through assembly
44
- # :add_file_attributes = optional - a boolean to indicate if publish/preserve/shelve/role attributes should be added using defaults or by supplied override by mime/type, defaults to false and is not required if project goes through assembly
45
- # :file_attributes = optional - a hash of file attributes by mimetype to use instead of defaults, only used if add_file_attributes is also true,
46
- # If a mimetype match is not found in your hash, the default is used (either your supplied default or the gems).
47
- # e.g. {'default'=>{:preserve=>'yes',:shelve=>'yes',:publish=>'yes'},'image/tif'=>{:preserve=>'yes',:shelve=>'no',:publish=>'no'},'application/pdf'=>{:preserve=>'yes',:shelve=>'yes',:publish=>'yes'}}
48
- # :include_root_xml = optional - a boolean to indicate if the contentMetadata returned includes a root <?xml version="1.0"?> tag, defaults to true
49
- # :preserve_common_paths = optional - When creating the file "id" attribute, content metadata uses the "relative_path" attribute of the ObjectFile objects passed in. If the "relative_path" attribute is not set, the "path" attribute is used instead,
50
- # which includes a full path to the file. If the "preserve_common_paths" parameter is set to false or left off, then the common paths of all of the ObjectFile's passed in are removed from any "path" attributes. This should turn full paths into
51
- # the relative paths that are required in content metadata file id nodes. If you do not want this behavior, set "preserve_common_paths" to true. The default is false.
52
- # :flatten_folder_structure = optional - Will remove *all* folder structure when genearting file IDs (e.g. DPG subfolders like '00','05' will be removed) when generating file IDs. This is useful if the folder structure is flattened when staging files (like for DPG).
53
- # The default is false. If set to true, will override the "preserve_common_paths" parameter.
54
- # :auto_labels = optional - Will add automated resource labels (e.g. "File 1") when labels are not provided by the user. The default is true.
55
- # See https://consul.stanford.edu/pages/viewpage.action?spaceKey=chimera&title=DOR+content+types%2C+resource+types+and+interpretive+metadata for next two settings
56
- # :reading_order = optional - only valid for simple_book, can be 'rtl' or 'ltr'. The default is 'ltr'.
57
- # Example:
58
- # Assembly::ContentMetadata.create_content_metadata(:druid=>'druid:nx288wh8889',:style=>:simple_image,:objects=>object_files,:add_file_attributes=>false)
59
- def self.create_content_metadata(druid:, objects:, auto_labels: true,
60
- add_exif: false, bundle: :default, style: :simple_image,
61
- add_file_attributes: false, file_attributes: {},
62
- preserve_common_paths: false, flatten_folder_structure: false,
63
- include_root_xml: nil, reading_order: 'ltr')
64
-
65
- common_path = find_common_path(objects) unless preserve_common_paths # find common paths to all files provided if needed
66
-
67
- filesets = FileSetBuilder.build(bundle: bundle, objects: objects, style: style)
68
- config = Config.new(auto_labels: auto_labels,
69
- flatten_folder_structure: flatten_folder_structure,
70
- add_file_attributes: add_file_attributes,
71
- file_attributes: file_attributes,
72
- add_exif: add_exif,
73
- reading_order: reading_order,
74
- type: object_level_type(style))
75
-
76
- builder = NokogiriBuilder.build(druid: druid,
77
- filesets: filesets,
78
- common_path: common_path,
79
- config: config)
80
-
81
- if include_root_xml == false
82
- builder.doc.root.to_xml
83
- else
84
- builder.to_xml
85
- end
86
- end
87
-
88
- def self.special_dpg_folder?(folder)
89
- SPECIAL_DPG_FOLDERS.include?(folder)
90
- end
91
-
92
- def self.find_common_path(objects)
93
- all_paths = objects.flatten.map do |obj|
94
- raise "File '#{obj.path}' not found" unless obj.file_exists?
95
-
96
- obj.path # collect all of the filenames into an array
97
- end
98
-
99
- Assembly::ObjectFile.common_path(all_paths) # find common paths to all files provided if needed
100
- end
101
- private_class_method :find_common_path
102
-
103
- def self.object_level_type(style)
104
- Deprecation.warn(self, "the style #{style} is now deprecated and should not be used. This will be removed in assembly-objectfile 2.0") if DEPRECATED_STYLES.include? style
105
- raise "Supplied style (#{style}) not valid" unless (VALID_STYLES + DEPRECATED_STYLES).include? style
106
-
107
- case style
108
- when :simple_image
109
- 'image'
110
- when :simple_book, :book_with_pdf, :book_as_image
111
- 'book'
112
- else
113
- style.to_s
114
- end
115
- end
116
- end # class
117
- end # module
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Assembly
4
- # This class contains generic methods to operate on any file.
5
- class ObjectFile
6
- include Assembly::ObjectFileable
7
-
8
- # Class level method that given an array of strings, return the longest common initial path. Useful for removing a common path from a set of filenames when producing content metadata
9
- #
10
- # @param [Array] strings Array of filenames with paths to operate on
11
- # @return [String] Common part of path of filenames passed in
12
- #
13
- # Example:
14
- # puts Assembly::ObjectFile.common_prefix(['/Users/peter/00/test.tif','/Users/peter/05/test.jp2']) # '/Users/peter/0'
15
- def self.common_path(strings)
16
- return nil if strings.empty?
17
-
18
- n = 0
19
- x = strings.last
20
- n += 1 while strings.all? { |s| s[n] && (s[n] == x[n]) }
21
- common_prefix = x[0...n]
22
- if common_prefix[-1, 1] == '/' # check if last element of the common string is the end of a directory
23
- common_prefix # if not, split string along directories, and reject last one
24
- else
25
- "#{common_prefix.split('/')[0..-2].join('/')}/" # if it was, then return the common prefix directly
26
- end
27
- end
28
- end
29
- end
Binary file
Binary file
Binary file