wax_iiif 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +25 -0
  4. data/.travis.yml +2 -2
  5. data/Gemfile +3 -2
  6. data/README.md +4 -4
  7. data/lib/wax_iiif.rb +34 -44
  8. data/lib/wax_iiif/base_properties.rb +90 -0
  9. data/lib/wax_iiif/builder.rb +252 -0
  10. data/lib/wax_iiif/collection.rb +58 -0
  11. data/lib/{iiif_s3 → wax_iiif}/config.rb +46 -60
  12. data/lib/{iiif_s3 → wax_iiif}/errors.rb +6 -12
  13. data/lib/{iiif_s3 → wax_iiif}/full_image.rb +3 -8
  14. data/lib/wax_iiif/image_info.rb +89 -0
  15. data/lib/{iiif_s3 → wax_iiif}/image_record.rb +48 -63
  16. data/lib/{iiif_s3 → wax_iiif}/image_tile.rb +8 -14
  17. data/lib/{iiif_s3 → wax_iiif}/image_variant.rb +20 -38
  18. data/lib/wax_iiif/manifest.rb +151 -0
  19. data/lib/{iiif_s3 → wax_iiif}/thumbnail.rb +5 -9
  20. data/lib/{iiif_s3 → wax_iiif}/utilities.rb +5 -5
  21. data/lib/{iiif_s3 → wax_iiif}/utilities/helpers.rb +18 -48
  22. data/lib/{iiif_s3 → wax_iiif}/utilities/pdf_splitter.rb +20 -23
  23. data/spec/base_properties_spec.rb +8 -12
  24. data/spec/shared_contexts.rb +28 -92
  25. data/spec/spec_helper.rb +3 -3
  26. data/spec/wax_iiif/builder_spec.rb +143 -0
  27. data/spec/wax_iiif/collection_spec.rb +53 -0
  28. data/spec/wax_iiif/config_spec.rb +15 -0
  29. data/spec/wax_iiif/image_info_spec.rb +57 -0
  30. data/spec/wax_iiif/image_record_spec.rb +82 -0
  31. data/spec/wax_iiif/image_variant_spec.rb +66 -0
  32. data/spec/wax_iiif/manifest_spec.rb +97 -0
  33. data/spec/wax_iiif/utilities/pdf_splitter_spec.rb +14 -0
  34. data/wax_iiif.gemspec +15 -19
  35. metadata +52 -97
  36. data/Guardfile +0 -10
  37. data/Rakefile +0 -24
  38. data/lib/iiif_s3/base_properties.rb +0 -95
  39. data/lib/iiif_s3/builder.rb +0 -241
  40. data/lib/iiif_s3/collection.rb +0 -61
  41. data/lib/iiif_s3/image_info.rb +0 -96
  42. data/lib/iiif_s3/manifest.rb +0 -151
  43. data/lib/iiif_s3/version.rb +0 -5
  44. data/spec/iiif_s3/builder_spec.rb +0 -152
  45. data/spec/iiif_s3/collection_spec.rb +0 -68
  46. data/spec/iiif_s3/config_spec.rb +0 -15
  47. data/spec/iiif_s3/image_info_spec.rb +0 -57
  48. data/spec/iiif_s3/image_record_spec.rb +0 -96
  49. data/spec/iiif_s3/image_variant_spec.rb +0 -68
  50. data/spec/iiif_s3/manifest_spec.rb +0 -97
  51. data/spec/iiif_s3/utilities/pdf_splitter_spec.rb +0 -17
  52. data/test.rb +0 -77
@@ -1,96 +0,0 @@
1
- require 'spec_helper'
2
- require "base_properties_spec"
3
-
4
-
5
- describe IiifS3::ImageRecord do
6
- let(:opts) {{
7
- id: 1
8
- }}
9
- let(:image_record) {IiifS3::ImageRecord.new(opts)}
10
-
11
- it "initializes without an error" do
12
- expect{IiifS3::ImageRecord.new}.not_to raise_error
13
- end
14
- it "initializes without an error when provided a hash" do
15
- opts = {id: 1}
16
- expect{IiifS3::ImageRecord.new(opts)}.not_to raise_error
17
- end
18
-
19
- context "#viewing_direction" do
20
- it "has a sensible default" do
21
- expect(image_record.viewing_direction).to eq IiifS3::DEFAULT_VIEWING_DIRECTION
22
- end
23
-
24
- it "rejects invalid viewing directions on init" do
25
- opts = {viewing_direction: "wonky"}
26
- expect{IiifS3::ImageRecord.new(opts)}.to raise_error(IiifS3::Error::InvalidViewingDirection)
27
- end
28
-
29
- it "rejects setting invalid viewing directions" do
30
- expect{image_record.viewing_direction = "wonky"}.to raise_error(IiifS3::Error::InvalidViewingDirection)
31
- end
32
- end
33
-
34
- it "initializes with provided hash values" do
35
- expect(image_record.id).to eq opts[:id]
36
- end
37
- it "ignores unknown data" do
38
- opts["junk_data"] = "bozo"
39
- expect{IiifS3::ImageRecord.new(opts)}.not_to raise_error
40
- end
41
- context "#is_primary" do
42
- it "defaults to false" do
43
- image_record.page_number = 2
44
- expect(image_record.is_primary).to equal(false)
45
- end
46
- it "defaults to true for first pages" do
47
- image_record.page_number = 1
48
- expect(image_record.is_primary).to equal(true)
49
- end
50
- it "has an alias" do
51
- image_record.page_number = 1
52
- expect(image_record.is_primary?).to equal(true)
53
- end
54
- it "forces is_primary to boolean" do
55
- image_record.is_primary = "banana"
56
- expect(image_record.is_primary).to equal(true)
57
- end
58
- it "uses page_number for intellegent defaults" do
59
- image_record.page_number = 1
60
- expect(image_record.is_primary).to equal(true)
61
- end
62
- it "allows page_number default to be overridded" do
63
- image_record.page_number = 1
64
- image_record.is_primary = false
65
- expect(image_record.is_primary).to equal(false)
66
- end
67
- end
68
- context "#image_path" do
69
- it "raises on a blan path" do
70
- expect{image_record.path = nil}.to raise_error(IiifS3::Error::InvalidImageData)
71
- end
72
- it "raises an error for a bad file name" do
73
- expect{image_record.path = "imaginary_file.jpg"}.to raise_error(IiifS3::Error::InvalidImageData)
74
- end
75
- end
76
- context "#section" do
77
- it "uses the default for the name" do
78
- expect(image_record.section).to eq DEFAULT_CANVAS_LABEL
79
- end
80
- it "uses the default for the label" do
81
- expect(image_record.section_label).to eq DEFAULT_CANVAS_LABEL
82
- end
83
- end
84
- context "#is_document" do
85
- it "defaults to false" do
86
- expect(image_record.is_document).to equal(false)
87
- end
88
- it "has_an_alias" do
89
- expect(image_record.is_document?).to equal(false)
90
- end
91
- it "forces is_document to boolean" do
92
- image_record.is_document = "banana"
93
- expect(image_record.is_document).to equal(true)
94
- end
95
- end
96
- end
@@ -1,68 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe IiifS3::ImageVariant do
4
- let(:config) {IiifS3::Config.new}
5
- let(:data) { IiifS3::ImageRecord.new({
6
- "path" => "./spec/data/test.jpg",
7
- "id" => 1,
8
- "page_number" => 1
9
- }) }
10
-
11
- context "initialization errors" do
12
- it "raises if the image does not have an ID" do
13
- data.id =nil
14
- expect{IiifS3::ImageVariant.new(data, config)}.to raise_error(IiifS3::Error::InvalidImageData)
15
- end
16
- it "raises if the image has a blank ID" do
17
- data.id = ""
18
- expect{IiifS3::ImageVariant.new(data, config)}.to raise_error(IiifS3::Error::InvalidImageData)
19
- end
20
-
21
- it "raises if the image is not a valid image file" do
22
- data.path = "./spec/data/test.csv"
23
- expect{IiifS3::ImageVariant.new(data, config)}.to raise_error(IiifS3::Error::InvalidImageData)
24
- end
25
-
26
- end
27
-
28
- context "basic data" do
29
- before(:all) do
30
- data = IiifS3::ImageRecord.new({
31
- "path" => "./spec/data/test.jpg",
32
- "id" => 1,
33
- "page_number" => 1
34
- })
35
- config = IiifS3::Config.new
36
- @img = IiifS3::ImageVariant.new(data, config, 100)
37
- end
38
-
39
- it "has a uri" do
40
- expect(@img.uri).to eq("#{@img.generate_image_id(1,1)}/full/100,/0/default.jpg")
41
- end
42
- it "has an id" do
43
- expect(@img.id).to eq("#{@img.generate_image_id(1,1)}")
44
- end
45
- it "has a width" do
46
- expect(@img.width).to eq(100)
47
- end
48
- it "has a mime type" do
49
- expect(@img.mime_type).to eq("image/jpeg")
50
- end
51
- end
52
-
53
- context "Full Image" do
54
- before(:all) do
55
- data = IiifS3::ImageRecord.new({
56
- "path" => "./spec/data/test.jpg",
57
- "id" => 1,
58
- "page_number" => 1
59
- })
60
- config = IiifS3::Config.new
61
- @img = IiifS3::FullImage.new(data, config)
62
- end
63
- it "has the default filestring" do
64
- expect(@img.uri).to include "full/full"
65
- end
66
-
67
- end
68
- end
@@ -1,97 +0,0 @@
1
- require 'spec_helper'
2
- require "base_properties_spec"
3
-
4
-
5
- describe IiifS3::Manifest do
6
- include_context("fake data")
7
-
8
- context "base" do
9
- before(:each) do
10
- @object = m
11
- end
12
- it_behaves_like "base properties"
13
- end
14
-
15
- let (:config) {IiifS3::Config.new()}
16
- let (:m) {IiifS3::Manifest.new([@fake_data],config)}
17
- let (:output) {JSON.parse(m.to_json)}
18
-
19
- it "initializes without an error" do
20
- expect(m).to be_a(IiifS3::Manifest)
21
- end
22
-
23
-
24
- it "exports JSON-LD as a valid JSON string" do
25
- expect(m.to_json).to be_a(String)
26
- expect{JSON.parse(m.to_json)}.not_to raise_error
27
- end
28
-
29
- it "has a @context" do
30
- expect(output["@context"]).to eq(IiifS3::PRESENTATION_CONTEXT)
31
- end
32
- it "has a @type" do
33
- expect(output["@type"]).to eq(IiifS3::Manifest::TYPE)
34
- end
35
- it "has an @id" do
36
- expect(output["@id"]).to eq("#{IiifS3::Config::DEFAULT_URL}/1/manifest.json")
37
- end
38
-
39
- context "error checking" do
40
- it "throws an error if not provided ImageRecords" do
41
- expect{IiifS3::Manifest.new(["not an image record"],config)}.to raise_error(IiifS3::Error::InvalidImageData)
42
- end
43
- it "throws an error unless there's a primary image" do
44
- data = @fake_data.clone
45
- data.is_primary = false
46
- expect{IiifS3::Manifest.new([data],config)}.to raise_error(IiifS3::Error::InvalidImageData)
47
- end
48
- it "throws an error if there are two primary images" do
49
- data1 = IiifS3::ImageRecord.new({is_primary: true})
50
- data2 = IiifS3::ImageRecord.new({is_primary: true})
51
-
52
- expect{IiifS3::Manifest.new([data1, data2],config)}.to raise_error(IiifS3::Error::MultiplePrimaryImages)
53
- end
54
- end
55
-
56
- context "config variables" do
57
- let (:config) {IiifS3::Config.new({:use_extensions => false})}
58
- it "the @id has an extension if configured thusly" do
59
- expect(output["@id"]).to eq("#{IiifS3::Config::DEFAULT_URL}/1/manifest")
60
- end
61
- end
62
-
63
- context "base_url config variable" do
64
- let (:config) {IiifS3::Config.new({base_url: "http://www.example.com"})}
65
- it "uses non-test uris" do
66
- expect(output["@id"]).to eq("http://www.example.com/1/manifest.json")
67
- end
68
- end
69
-
70
- context "spec requirements" do
71
- it "has a label" do
72
- expect(output["label"].length).to be > 0
73
- end
74
- it "does not have a format" do
75
- expect(output["format"]).to be_nil
76
- end
77
- it "does not have a height" do
78
- expect(output["height"]).to be_nil
79
- end
80
- it "does not have a width" do
81
- expect(output["width"]).to be_nil
82
- end
83
- it "does not have a startCanvas" do
84
- expect(output["startCanvas"]).to be_nil
85
- end
86
- it "accepts valid viewing directions" do
87
- dir = "right-to-left"
88
- new_data = @fake_data
89
- new_data.viewing_direction = dir
90
- m = IiifS3::Manifest.new([new_data],config)
91
- o = JSON.parse(m.to_json)
92
- expect(o["viewingDirection"]).to eq(dir)
93
-
94
- end
95
- end
96
-
97
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
-
3
-
4
- describe IiifS3::Utilities::PdfSplitter do
5
- context "comparing" do
6
- it "generates the proper number of files" do
7
- skip("skipping expensive tests") if ENV["SKIP_EXPENSIVE_TESTS"]
8
- Dir.mktmpdir do |dir|
9
- results = IiifS3::Utilities::PdfSplitter.split("./spec/data/test.pdf", output_dir: dir)
10
- expect(results.count).to eq(3)
11
- results.each do |file|
12
- File.delete(file)
13
- end
14
- end
15
- end
16
- end
17
- end
data/test.rb DELETED
@@ -1,77 +0,0 @@
1
- require 'dotenv'
2
- Dotenv.load
3
-
4
- require_relative 'lib/wax_iiif'
5
-
6
- # Set up configuration variables
7
- opts = {}
8
- opts[:image_directory_name] = "img"
9
- opts[:variants] = { "reference" => 600, "access" => 1200}
10
- opts[:image_types] = [".jpg", ".tif", ".jpeg", ".tiff"]
11
- opts[:document_file_types] = [".pdf"]
12
-
13
- # Setup Temporary stores
14
- @data = []
15
- @cleanup_list = []
16
- @dir = "./data"
17
-
18
-
19
- def add_image(file, is_doc = false)
20
- name = File.basename(file, File.extname(file))
21
- name_parts = name.split("_")
22
- is_paged = name_parts.length == 8
23
- page_num = is_paged ? name_parts[7].to_i : 1
24
- name_parts.pop if is_paged
25
- id = name_parts.join("_")
26
-
27
- obj = {
28
- "path" => "#{file}",
29
- "id" => id,
30
- "label" => name_parts.join("."),
31
- "is_master" => page_num == 1,
32
- "page_number" => page_num,
33
- "is_document" => false,
34
- "description" => "This is a test file generated as part of the development on the ruby IiifS3 Gem. <b> This should be bold.</b>"
35
- }
36
-
37
- if is_paged
38
- obj["section"] = "p#{page_num}"
39
- obj["section_label"] = "Page #{page_num}"
40
- end
41
-
42
- if is_doc
43
- obj["is_document"] = true
44
- end
45
- @data.push IiifS3::ImageRecord.new(obj)
46
- end
47
-
48
- def add_to_cleanup_list(img)
49
- @cleanup_list.push(img)
50
- end
51
-
52
- def cleanup
53
- @cleanup_list.each do |file|
54
- File.delete(file)
55
- end
56
- end
57
-
58
-
59
- iiif = IiifS3::Builder.new(opts)
60
- iiif.create_build_directories
61
-
62
- Dir.foreach(@dir) do |file|
63
- if opts[:image_file_types].include? File.extname(file)
64
- add_image("#{@dir}/#{file}")
65
- elsif opts[:document_file_types].include? File.extname(file)
66
- path = "#{@dir}/#{file}"
67
- images = IiifS3::Utilities::PdfSplitter.split(path)
68
- images.each do |img|
69
- add_image(img, true)
70
- add_to_cleanup_list(img)
71
- end
72
- end
73
- end
74
-
75
- iiif.load(@data)
76
- iiif.process_data
77
- cleanup