iiif-presentation 1.4.2 → 1.5.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.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +8 -1
- data/.standard.yml +1 -0
- data/Gemfile +5 -5
- data/README.md +1 -1
- data/Rakefile +4 -2
- data/VERSION +1 -1
- data/bin/standardrb +16 -0
- data/iiif-presentation.gemspec +23 -23
- data/lib/iiif/hash_behaviours.rb +29 -33
- data/lib/iiif/ordered_hash.rb +33 -33
- data/lib/iiif/presentation/abstract_resource.rb +17 -22
- data/lib/iiif/presentation/annotation.rb +9 -11
- data/lib/iiif/presentation/annotation_list.rb +8 -10
- data/lib/iiif/presentation/canvas.rb +11 -13
- data/lib/iiif/presentation/collection.rb +7 -9
- data/lib/iiif/presentation/image_resource.rb +33 -35
- data/lib/iiif/presentation/layer.rb +8 -10
- data/lib/iiif/presentation/manifest.rb +9 -12
- data/lib/iiif/presentation/range.rb +8 -10
- data/lib/iiif/presentation/resource.rb +5 -7
- data/lib/iiif/presentation/sequence.rb +8 -11
- data/lib/iiif/presentation/service.rb +1 -2
- data/lib/iiif/presentation.rb +7 -7
- data/lib/iiif/service.rb +121 -102
- data/lib/iiif/v3/abstract_resource.rb +127 -130
- data/lib/iiif/v3/presentation/annotation.rb +20 -21
- data/lib/iiif/v3/presentation/annotation_collection.rb +7 -9
- data/lib/iiif/v3/presentation/annotation_page.rb +14 -15
- data/lib/iiif/v3/presentation/canvas.rb +21 -22
- data/lib/iiif/v3/presentation/choice.rb +14 -15
- data/lib/iiif/v3/presentation/collection.rb +7 -8
- data/lib/iiif/v3/presentation/image_resource.rb +21 -22
- data/lib/iiif/v3/presentation/manifest.rb +18 -19
- data/lib/iiif/v3/presentation/nav_place.rb +125 -29
- data/lib/iiif/v3/presentation/range.rb +10 -10
- data/lib/iiif/v3/presentation/resource.rb +4 -5
- data/lib/iiif/v3/presentation/sequence.rb +10 -11
- data/lib/iiif/v3/presentation/service.rb +12 -13
- data/lib/iiif/v3/presentation.rb +8 -8
- data/spec/integration/iiif/presentation/image_resource_spec.rb +54 -58
- data/spec/integration/iiif/service_spec.rb +76 -77
- data/spec/integration/iiif/v3/abstract_resource_spec.rb +72 -73
- data/spec/integration/iiif/v3/presentation/image_resource_spec.rb +53 -56
- data/spec/spec_helper.rb +56 -64
- data/spec/unit/iiif/hash_behaviours_spec.rb +384 -387
- data/spec/unit/iiif/ordered_hash_spec.rb +86 -91
- data/spec/unit/iiif/presentation/abstract_resource_spec.rb +64 -70
- data/spec/unit/iiif/presentation/annotation_list_spec.rb +1 -3
- data/spec/unit/iiif/presentation/annotation_spec.rb +1 -3
- data/spec/unit/iiif/presentation/canvas_spec.rb +11 -14
- data/spec/unit/iiif/presentation/collection_spec.rb +26 -33
- data/spec/unit/iiif/presentation/image_resource_spec.rb +4 -6
- data/spec/unit/iiif/presentation/layer_spec.rb +16 -20
- data/spec/unit/iiif/presentation/manifest_spec.rb +45 -48
- data/spec/unit/iiif/presentation/range_spec.rb +18 -22
- data/spec/unit/iiif/presentation/resource_spec.rb +3 -6
- data/spec/unit/iiif/presentation/sequence_spec.rb +58 -63
- data/spec/unit/iiif/presentation/shared_examples/abstract_resource_only_keys.rb +4 -10
- data/spec/unit/iiif/presentation/shared_examples/any_type_keys.rb +5 -9
- data/spec/unit/iiif/presentation/shared_examples/array_only_keys.rb +9 -17
- data/spec/unit/iiif/presentation/shared_examples/int_only_keys.rb +6 -14
- data/spec/unit/iiif/presentation/shared_examples/string_only_keys.rb +6 -13
- data/spec/unit/iiif/service_spec.rb +8 -13
- data/spec/unit/iiif/v3/abstract_resource_define_methods_for_spec.rb +39 -37
- data/spec/unit/iiif/v3/abstract_resource_spec.rb +124 -131
- data/spec/unit/iiif/v3/presentation/annotation_collection_spec.rb +14 -17
- data/spec/unit/iiif/v3/presentation/annotation_page_spec.rb +71 -69
- data/spec/unit/iiif/v3/presentation/annotation_spec.rb +249 -233
- data/spec/unit/iiif/v3/presentation/canvas_spec.rb +211 -193
- data/spec/unit/iiif/v3/presentation/choice_spec.rb +81 -77
- data/spec/unit/iiif/v3/presentation/collection_spec.rb +24 -29
- data/spec/unit/iiif/v3/presentation/image_resource_spec.rb +70 -71
- data/spec/unit/iiif/v3/presentation/manifest_spec.rb +248 -235
- data/spec/unit/iiif/v3/presentation/nav_place_spec.rb +249 -49
- data/spec/unit/iiif/v3/presentation/range_spec.rb +28 -29
- data/spec/unit/iiif/v3/presentation/resource_spec.rb +83 -82
- data/spec/unit/iiif/v3/presentation/sequence_spec.rb +125 -119
- data/spec/unit/iiif/v3/presentation/service_spec.rb +123 -124
- data/spec/unit/iiif/v3/presentation/shared_examples/abstract_resource_only_keys.rb +4 -8
- data/spec/unit/iiif/v3/presentation/shared_examples/any_type_keys.rb +5 -7
- data/spec/unit/iiif/v3/presentation/shared_examples/array_only_keys.rb +9 -13
- data/spec/unit/iiif/v3/presentation/shared_examples/hash_only_keys.rb +9 -13
- data/spec/unit/iiif/v3/presentation/shared_examples/int_only_keys.rb +6 -10
- data/spec/unit/iiif/v3/presentation/shared_examples/numeric_only_keys.rb +6 -10
- data/spec/unit/iiif/v3/presentation/shared_examples/string_only_keys.rb +6 -10
- data/spec/unit/iiif/v3/presentation/shared_examples/uri_only_keys.rb +9 -13
- metadata +26 -65
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cc1d6696459ce980fb1c2b41a48ff98f97c25096e72fe803eedbe058e73031ed
|
|
4
|
+
data.tar.gz: cb0e7e02ae09625490473a11fac3eb8680ae91ae43279311b1c41f922df1c578
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 075fbdad767e99ccf4b8e197b5fef5c0fdd658a7a59e6f9c37845f17147d7069441fc031915c3eba1116e5a86c4056ec6dc0eec86eb32c8846efbc92be5f0c82
|
|
7
|
+
data.tar.gz: fa4986c26803ebb8abaa71571ed982475ecd1f6ccad4d170ca48e98352cae3477e0a6b7c4c5f9aeddcecc13208ed8f359161882e76cde71e8af9c91122d71208
|
data/.github/workflows/ruby.yml
CHANGED
|
@@ -22,7 +22,7 @@ jobs:
|
|
|
22
22
|
runs-on: ubuntu-latest
|
|
23
23
|
strategy:
|
|
24
24
|
matrix:
|
|
25
|
-
ruby-version: ['
|
|
25
|
+
ruby-version: ['3.3', '3.4', '4.0']
|
|
26
26
|
|
|
27
27
|
steps:
|
|
28
28
|
- uses: actions/checkout@v3
|
|
@@ -33,3 +33,10 @@ jobs:
|
|
|
33
33
|
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
|
34
34
|
- name: Run tests
|
|
35
35
|
run: bundle exec rake
|
|
36
|
+
- name: Upload coverage to Coveralls
|
|
37
|
+
if: matrix.ruby-version == '4.0'
|
|
38
|
+
uses: coverallsapp/github-action@v2
|
|
39
|
+
with:
|
|
40
|
+
file: coverage/.resultset.json
|
|
41
|
+
format: simplecov
|
|
42
|
+
fail-on-error: false
|
data/.standard.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ruby_version: 3.3
|
data/Gemfile
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
source "https://rubygems.org"
|
|
2
2
|
gemspec
|
|
3
3
|
|
|
4
|
-
if ENV[
|
|
5
|
-
gem
|
|
4
|
+
if ENV["RAILS_VERSION"]
|
|
5
|
+
gem "activesupport", ENV["RAILS_VERSION"]
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
-
if ENV[
|
|
9
|
-
gem
|
|
8
|
+
if ENV["FARADAY_VERSION"]
|
|
9
|
+
gem "faraday", ENV["FARADAY_VERSION"]
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
gem
|
|
12
|
+
gem "debug"
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# O'Sullivan: A Ruby API for working with IIIF Presentation manifests
|
|
2
2
|
|
|
3
|
-
[](https://coveralls.io/github/iiif-prezi/osullivan?branch=main)
|
|
4
4
|
[](https://badge.fury.io/rb/iiif-presentation)
|
|
5
5
|
|
|
6
6
|
|
data/Rakefile
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env rake
|
|
2
2
|
|
|
3
3
|
require "bundler/gem_tasks"
|
|
4
|
-
require
|
|
4
|
+
require "rspec/core/rake_task"
|
|
5
|
+
require "standard/rake"
|
|
5
6
|
|
|
6
7
|
RSpec::Core::RakeTask.new(:spec)
|
|
7
8
|
|
|
8
9
|
task :ci do
|
|
9
|
-
Rake::Task[
|
|
10
|
+
Rake::Task["standard"].invoke
|
|
11
|
+
Rake::Task["spec"].invoke
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
task default: :ci
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.
|
|
1
|
+
1.5.0
|
data/bin/standardrb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# This file was generated by Bundler.
|
|
6
|
+
#
|
|
7
|
+
# The application 'standardrb' is installed as part of a gem, and
|
|
8
|
+
# this file is here to facilitate running it.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
|
12
|
+
|
|
13
|
+
require "rubygems"
|
|
14
|
+
require "bundler/setup"
|
|
15
|
+
|
|
16
|
+
load Gem.bin_path("standard", "standardrb")
|
data/iiif-presentation.gemspec
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
version = File.read(File.expand_path(
|
|
1
|
+
version = File.read(File.expand_path("../VERSION", __FILE__)).strip
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |spec|
|
|
4
|
-
spec.name
|
|
5
|
-
spec.version
|
|
6
|
-
spec.authors
|
|
7
|
-
spec.email
|
|
8
|
-
spec.description
|
|
9
|
-
spec.summary
|
|
10
|
-
spec.license
|
|
11
|
-
spec.homepage
|
|
4
|
+
spec.name = "iiif-presentation"
|
|
5
|
+
spec.version = version
|
|
6
|
+
spec.authors = ["Jon Stroop"]
|
|
7
|
+
spec.email = ["jpstroop@gmail.com"]
|
|
8
|
+
spec.description = "API for working with IIIF Presentation manifests."
|
|
9
|
+
spec.summary = "API for working with IIIF Presentation manifests."
|
|
10
|
+
spec.license = "Simplified BSD"
|
|
11
|
+
spec.homepage = "https://github.com/iiif/osullivan"
|
|
12
12
|
|
|
13
|
-
spec.files
|
|
14
|
-
spec.
|
|
15
|
-
spec.require_paths = ['lib']
|
|
13
|
+
spec.files = `git ls-files`.split($/)
|
|
14
|
+
spec.require_paths = ["lib"]
|
|
16
15
|
|
|
17
|
-
spec.add_development_dependency
|
|
18
|
-
spec.add_development_dependency
|
|
19
|
-
spec.add_development_dependency
|
|
20
|
-
spec.add_development_dependency
|
|
21
|
-
spec.add_development_dependency
|
|
22
|
-
spec.add_development_dependency
|
|
23
|
-
spec.add_development_dependency
|
|
16
|
+
spec.add_development_dependency "bundler"
|
|
17
|
+
spec.add_development_dependency "rake"
|
|
18
|
+
spec.add_development_dependency "rspec"
|
|
19
|
+
spec.add_development_dependency "simplecov", "~> 1.3"
|
|
20
|
+
spec.add_development_dependency "webmock"
|
|
21
|
+
spec.add_development_dependency "multi_json"
|
|
22
|
+
spec.add_development_dependency "vcr", "~> 6.4"
|
|
23
|
+
spec.add_development_dependency "standard"
|
|
24
24
|
|
|
25
|
-
spec.add_dependency
|
|
26
|
-
spec.add_dependency
|
|
27
|
-
spec.add_dependency
|
|
28
|
-
spec.add_dependency
|
|
25
|
+
spec.add_dependency "json"
|
|
26
|
+
spec.add_dependency "activesupport", ">= 3.2.18"
|
|
27
|
+
spec.add_dependency "faraday", "~> 2.7"
|
|
28
|
+
spec.add_dependency "geo_coord"
|
|
29
29
|
end
|
data/lib/iiif/hash_behaviours.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "forwardable"
|
|
2
2
|
|
|
3
3
|
module IIIF
|
|
4
4
|
module HashBehaviours
|
|
@@ -9,10 +9,9 @@ module IIIF
|
|
|
9
9
|
# * replace
|
|
10
10
|
|
|
11
11
|
def_delegators :@data, :[], :[]=, :camelize_keys, :delete, :dig, :empty?,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
:fetch, :has_key?, :has_value?, :include?, :insert, :insert_after,
|
|
13
|
+
:insert_before, :key, :key?, :keys, :length, :member?, :shift, :size,
|
|
14
|
+
:snakeize_keys, :store, :unshift, :value?, :values
|
|
16
15
|
|
|
17
16
|
###
|
|
18
17
|
# Methods that take a block and should return an instance (self or a new'
|
|
@@ -23,11 +22,11 @@ module IIIF
|
|
|
23
22
|
|
|
24
23
|
SIMPLE_SELF_RETURNERS.each do |method_name|
|
|
25
24
|
define_method(method_name) do |*arg, &block|
|
|
26
|
-
|
|
27
|
-
@data.send(method_name, *arg, &block)
|
|
28
|
-
return self
|
|
29
|
-
else
|
|
25
|
+
if block.nil?
|
|
30
26
|
@data.send(method_name)
|
|
27
|
+
else # block_given? doesn't seem to work in this context
|
|
28
|
+
@data.send(method_name, *arg, &block)
|
|
29
|
+
self
|
|
31
30
|
end
|
|
32
31
|
end
|
|
33
32
|
end
|
|
@@ -35,7 +34,7 @@ module IIIF
|
|
|
35
34
|
# Clear is the only method that returns self but doesn't accept a block
|
|
36
35
|
def clear
|
|
37
36
|
@data.clear
|
|
38
|
-
|
|
37
|
+
self
|
|
39
38
|
end
|
|
40
39
|
|
|
41
40
|
# Returns a new instance of this class containing the contents of'
|
|
@@ -53,19 +52,19 @@ module IIIF
|
|
|
53
52
|
# by calling the block with the key, its value in hsh and its value in'
|
|
54
53
|
# another_obj.
|
|
55
54
|
def merge another_obj
|
|
56
|
-
new_instance =
|
|
55
|
+
new_instance = self.class.new
|
|
57
56
|
# self.clone # Would this be better? What happens to other attributes of the class?
|
|
58
57
|
if block_given?
|
|
59
|
-
|
|
60
|
-
if another_obj.has_key? k
|
|
61
|
-
|
|
58
|
+
each do |k, v|
|
|
59
|
+
new_instance[k] = if another_obj.has_key? k
|
|
60
|
+
yield(k, self[k], another_obj[k])
|
|
62
61
|
else
|
|
63
|
-
|
|
62
|
+
v
|
|
64
63
|
end
|
|
65
64
|
end
|
|
66
65
|
else
|
|
67
|
-
|
|
68
|
-
another_obj.each { |k,v| new_instance[k] = v }
|
|
66
|
+
each { |k, v| new_instance[k] = v }
|
|
67
|
+
another_obj.each { |k, v| new_instance[k] = v }
|
|
69
68
|
end
|
|
70
69
|
new_instance
|
|
71
70
|
end
|
|
@@ -85,20 +84,20 @@ module IIIF
|
|
|
85
84
|
# another_obj.
|
|
86
85
|
def merge! another_obj
|
|
87
86
|
if block_given?
|
|
88
|
-
|
|
89
|
-
if another_obj.has_key? k
|
|
90
|
-
|
|
87
|
+
each do |k, v|
|
|
88
|
+
self[k] = if another_obj.has_key? k
|
|
89
|
+
yield(k, self[k], another_obj[k])
|
|
91
90
|
else
|
|
92
|
-
|
|
91
|
+
v
|
|
93
92
|
end
|
|
94
93
|
end
|
|
95
94
|
else
|
|
96
|
-
|
|
97
|
-
another_obj.each { |k,v| self[k] = v }
|
|
95
|
+
each { |k, v| self[k] = v }
|
|
96
|
+
another_obj.each { |k, v| self[k] = v }
|
|
98
97
|
end
|
|
99
98
|
self
|
|
100
99
|
end
|
|
101
|
-
|
|
100
|
+
alias_method :update, :merge!
|
|
102
101
|
|
|
103
102
|
# Deletes entries for which the supplied block evaluates to true.
|
|
104
103
|
# Equivalent to #delete_if, but returns nil if there were no changes
|
|
@@ -111,9 +110,9 @@ module IIIF
|
|
|
111
110
|
return_nil = false
|
|
112
111
|
end
|
|
113
112
|
end
|
|
114
|
-
|
|
113
|
+
return_nil ? nil : self
|
|
115
114
|
else
|
|
116
|
-
|
|
115
|
+
data.reject!
|
|
117
116
|
end
|
|
118
117
|
end
|
|
119
118
|
|
|
@@ -123,9 +122,9 @@ module IIIF
|
|
|
123
122
|
def select
|
|
124
123
|
new_instance = self.class.new
|
|
125
124
|
if block_given?
|
|
126
|
-
@data.each { |k,v| new_instance.data[k] = v if yield(k,v) }
|
|
125
|
+
@data.each { |k, v| new_instance.data[k] = v if yield(k, v) }
|
|
127
126
|
end
|
|
128
|
-
|
|
127
|
+
new_instance
|
|
129
128
|
end
|
|
130
129
|
|
|
131
130
|
# Deletes entries for which the supplied block evaluates to false.
|
|
@@ -133,8 +132,8 @@ module IIIF
|
|
|
133
132
|
def select!
|
|
134
133
|
if block_given?
|
|
135
134
|
return_nil = true
|
|
136
|
-
@data.each do |k,v|
|
|
137
|
-
unless yield(k,v)
|
|
135
|
+
@data.each do |k, v|
|
|
136
|
+
unless yield(k, v)
|
|
138
137
|
@data.delete(k)
|
|
139
138
|
return_nil = false
|
|
140
139
|
end
|
|
@@ -143,8 +142,5 @@ module IIIF
|
|
|
143
142
|
end
|
|
144
143
|
self
|
|
145
144
|
end
|
|
146
|
-
|
|
147
145
|
end
|
|
148
|
-
|
|
149
146
|
end
|
|
150
|
-
|
data/lib/iiif/ordered_hash.rb
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "active_support/inflector"
|
|
2
2
|
|
|
3
3
|
module IIIF
|
|
4
4
|
class OrderedHash < ::Hash
|
|
5
|
-
|
|
6
5
|
# Insert a new key and value at the suppplied index.
|
|
7
6
|
#
|
|
8
7
|
# Note that this is slightly different from Array#insert in that new
|
|
@@ -14,24 +13,24 @@ module IIIF
|
|
|
14
13
|
# @param [Object] value
|
|
15
14
|
def insert(index, key, value)
|
|
16
15
|
tmp = IIIF::OrderedHash.new
|
|
17
|
-
index =
|
|
16
|
+
index = length + 1 + index if index < 0
|
|
18
17
|
if index < 0
|
|
19
18
|
m = "Index #{index} is too small for current length (#{length})"
|
|
20
19
|
raise IndexError, m
|
|
21
20
|
end
|
|
22
21
|
if index > 0
|
|
23
|
-
i=0
|
|
24
|
-
|
|
22
|
+
i = 0
|
|
23
|
+
each do |k, v|
|
|
25
24
|
tmp[k] = v
|
|
26
|
-
|
|
27
|
-
i+=1
|
|
25
|
+
delete(k)
|
|
26
|
+
i += 1
|
|
28
27
|
break if i == index
|
|
29
28
|
end
|
|
30
29
|
end
|
|
31
30
|
tmp[key] = value
|
|
32
31
|
tmp.merge!(self) # copy the remaining to tmp
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
clear # start over...
|
|
33
|
+
merge!(tmp) # now put them all back
|
|
35
34
|
self
|
|
36
35
|
end
|
|
37
36
|
|
|
@@ -49,9 +48,9 @@ module IIIF
|
|
|
49
48
|
new_key = hsh[:new_key]
|
|
50
49
|
value = hsh[:value]
|
|
51
50
|
if block_given?
|
|
52
|
-
|
|
51
|
+
insert_here(0, new_key, value, &block)
|
|
53
52
|
else
|
|
54
|
-
|
|
53
|
+
insert_here(0, new_key, value, existing_key)
|
|
55
54
|
end
|
|
56
55
|
end
|
|
57
56
|
|
|
@@ -69,27 +68,29 @@ module IIIF
|
|
|
69
68
|
new_key = hsh[:new_key]
|
|
70
69
|
value = hsh[:value]
|
|
71
70
|
if block_given?
|
|
72
|
-
|
|
71
|
+
insert_here(1, new_key, value, &block)
|
|
73
72
|
else
|
|
74
|
-
|
|
73
|
+
insert_here(1, new_key, value, existing_key)
|
|
75
74
|
end
|
|
76
75
|
end
|
|
77
76
|
|
|
78
77
|
# Delete any keys that are empty arrays
|
|
79
78
|
def remove_empties
|
|
80
|
-
|
|
81
|
-
if (self[key].
|
|
82
|
-
|
|
79
|
+
keys.each do |key|
|
|
80
|
+
if (self[key].is_a?(Array) && self[key].empty?) || self[key].nil?
|
|
81
|
+
delete(key)
|
|
83
82
|
end
|
|
84
83
|
end
|
|
85
84
|
end
|
|
86
85
|
|
|
87
86
|
# Covert snake_case keys to camelCase
|
|
88
87
|
def camelize_keys
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
88
|
+
keys.each_with_index do |key, i|
|
|
89
|
+
camelized_key = key.camelize(:lower)
|
|
90
|
+
|
|
91
|
+
if key != camelized_key
|
|
92
|
+
insert(i, camelized_key, self[key])
|
|
93
|
+
delete(key)
|
|
93
94
|
end
|
|
94
95
|
end
|
|
95
96
|
self
|
|
@@ -97,30 +98,30 @@ module IIIF
|
|
|
97
98
|
|
|
98
99
|
# Covert camelCase keys to snake_case
|
|
99
100
|
def snakeize_keys
|
|
100
|
-
|
|
101
|
+
keys.each_with_index do |key, i|
|
|
101
102
|
if key != key.underscore
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
insert(i, key.underscore, self[key])
|
|
104
|
+
delete(key)
|
|
104
105
|
end
|
|
105
106
|
end
|
|
106
107
|
self
|
|
107
108
|
end
|
|
108
109
|
|
|
109
|
-
|
|
110
110
|
# Prepends an entry to the front of the object.
|
|
111
111
|
# Note that this is slightly different from Array#unshift in that new
|
|
112
112
|
# entries must be added one at a time, i.e. unshift([k,v],[k,v],...) is
|
|
113
113
|
# not currently supported.
|
|
114
|
-
def unshift k,v
|
|
115
|
-
|
|
114
|
+
def unshift k, v
|
|
115
|
+
insert(0, k, v)
|
|
116
116
|
self
|
|
117
117
|
end
|
|
118
118
|
|
|
119
119
|
protected
|
|
120
|
-
|
|
120
|
+
|
|
121
|
+
def insert_here(where, new_key, value, existing_key = nil, &block)
|
|
121
122
|
idx = nil
|
|
122
123
|
if block_given?
|
|
123
|
-
|
|
124
|
+
each_with_index do |(k, v), i|
|
|
124
125
|
if yield(k, v)
|
|
125
126
|
idx = i
|
|
126
127
|
break
|
|
@@ -130,17 +131,16 @@ module IIIF
|
|
|
130
131
|
raise KeyError, "Supplied block never evaluates to true"
|
|
131
132
|
end
|
|
132
133
|
else
|
|
133
|
-
unless
|
|
134
|
+
unless has_key?(existing_key)
|
|
134
135
|
raise KeyError, "Existing key '#{existing_key}' does not exist"
|
|
135
136
|
end
|
|
136
|
-
if
|
|
137
|
+
if has_key?(new_key)
|
|
137
138
|
raise KeyError, "Supplied new key '#{new_key}' already exists"
|
|
138
139
|
end
|
|
139
|
-
idx =
|
|
140
|
+
idx = keys.index(existing_key) + where
|
|
140
141
|
end
|
|
141
|
-
|
|
142
|
+
insert(idx, new_key, value)
|
|
142
143
|
self
|
|
143
144
|
end
|
|
144
|
-
|
|
145
145
|
end
|
|
146
146
|
end
|
|
@@ -1,44 +1,43 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__),
|
|
1
|
+
require File.join(File.dirname(__FILE__), "../service")
|
|
2
2
|
|
|
3
3
|
module IIIF
|
|
4
4
|
module Presentation
|
|
5
5
|
class AbstractResource < Service
|
|
6
|
-
|
|
7
6
|
# Every subclass should override the following five methods where
|
|
8
7
|
# appropriate, see Subclasses for how.
|
|
9
8
|
def required_keys
|
|
10
|
-
%w
|
|
9
|
+
%w[@type]
|
|
11
10
|
end
|
|
12
11
|
|
|
13
12
|
def any_type_keys # these are allowed on all classes
|
|
14
|
-
%w
|
|
15
|
-
|
|
13
|
+
%w[ label description thumbnail attribution license logo see_also
|
|
14
|
+
related within ]
|
|
16
15
|
end
|
|
17
16
|
|
|
18
17
|
def string_only_keys
|
|
19
|
-
%w
|
|
18
|
+
%w[viewing_hint] # should any of the any_type_keys be here?
|
|
20
19
|
end
|
|
21
20
|
|
|
22
21
|
def array_only_keys
|
|
23
|
-
%w
|
|
22
|
+
%w[metadata]
|
|
24
23
|
end
|
|
25
24
|
|
|
26
25
|
def abstract_resource_only_keys
|
|
27
|
-
super + [
|
|
26
|
+
super + [{key: "service", type: IIIF::Service}]
|
|
28
27
|
end
|
|
29
28
|
|
|
30
29
|
def hash_only_keys
|
|
31
|
-
%w
|
|
30
|
+
%w[]
|
|
32
31
|
end
|
|
33
32
|
|
|
34
33
|
def int_only_keys
|
|
35
|
-
%w
|
|
34
|
+
%w[]
|
|
36
35
|
end
|
|
37
36
|
|
|
38
37
|
# Not every subclass is allowed to have viewingDirect, but when it is,
|
|
39
38
|
# it must be one of these values
|
|
40
39
|
def legal_viewing_direction_values
|
|
41
|
-
%w
|
|
40
|
+
%w[left-to-right right-to-left top-to-bottom bottom-to-top]
|
|
42
41
|
end
|
|
43
42
|
|
|
44
43
|
def legal_viewing_hint_values
|
|
@@ -49,30 +48,26 @@ module IIIF
|
|
|
49
48
|
# @param [Hash] hsh - Anything in this hash will be added to the Object.
|
|
50
49
|
# @param [boolean] include_context (default: false). Pass true if the'
|
|
51
50
|
# context should be included.
|
|
52
|
-
def initialize(hsh={})
|
|
53
|
-
if
|
|
51
|
+
def initialize(hsh = {})
|
|
52
|
+
if instance_of?(IIIF::Presentation::AbstractResource)
|
|
54
53
|
raise "#{self.class} is an abstract class. Please use one of its subclasses."
|
|
55
54
|
end
|
|
56
|
-
super
|
|
55
|
+
super
|
|
57
56
|
end
|
|
58
57
|
|
|
59
|
-
|
|
60
58
|
# Options:
|
|
61
59
|
# * force: (true|false). Skips validations.
|
|
62
60
|
# * include_context: (true|false). Adds the @context to the top of the
|
|
63
61
|
# document if it doesn't exist. Default: true.
|
|
64
62
|
# * sort_json_ld_keys: (true|false). Brings all properties starting with
|
|
65
63
|
# '@'. Default: true. to the top of the document and sorts them.
|
|
66
|
-
def to_ordered_hash(opts={})
|
|
64
|
+
def to_ordered_hash(opts = {})
|
|
67
65
|
include_context = opts.fetch(:include_context, true)
|
|
68
|
-
if include_context && !
|
|
69
|
-
self[
|
|
66
|
+
if include_context && !has_key?("@context")
|
|
67
|
+
self["@context"] = IIIF::Presentation::CONTEXT
|
|
70
68
|
end
|
|
71
|
-
super
|
|
69
|
+
super
|
|
72
70
|
end
|
|
73
|
-
|
|
74
71
|
end
|
|
75
|
-
|
|
76
72
|
end
|
|
77
73
|
end
|
|
78
|
-
|
|
@@ -1,29 +1,27 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__),
|
|
1
|
+
require File.join(File.dirname(__FILE__), "abstract_resource")
|
|
2
2
|
|
|
3
3
|
module IIIF
|
|
4
4
|
module Presentation
|
|
5
5
|
class Annotation < AbstractResource
|
|
6
|
-
|
|
7
|
-
TYPE = 'oa:Annotation'
|
|
6
|
+
TYPE = "oa:Annotation"
|
|
8
7
|
|
|
9
8
|
def required_keys
|
|
10
|
-
super + %w
|
|
9
|
+
super + %w[motivation on]
|
|
11
10
|
end
|
|
12
11
|
|
|
13
12
|
def string_only_keys
|
|
14
|
-
super + %w
|
|
13
|
+
super + %w[on]
|
|
15
14
|
end
|
|
16
15
|
|
|
17
16
|
def abstract_resource_only_keys
|
|
18
|
-
super + [
|
|
17
|
+
super + [{key: "resource", type: IIIF::Presentation::Resource}]
|
|
19
18
|
end
|
|
20
19
|
|
|
21
|
-
def initialize(hsh={})
|
|
22
|
-
hsh[
|
|
23
|
-
hsh[
|
|
24
|
-
super
|
|
20
|
+
def initialize(hsh = {})
|
|
21
|
+
hsh["@type"] = TYPE unless hsh.has_key? "@type"
|
|
22
|
+
hsh["motivation"] = "sc:painting" unless hsh.has_key? "motivation"
|
|
23
|
+
super
|
|
25
24
|
end
|
|
26
|
-
|
|
27
25
|
end
|
|
28
26
|
end
|
|
29
27
|
end
|
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__),
|
|
1
|
+
require File.join(File.dirname(__FILE__), "abstract_resource")
|
|
2
2
|
|
|
3
3
|
module IIIF
|
|
4
4
|
module Presentation
|
|
5
5
|
class AnnotationList < AbstractResource
|
|
6
|
-
|
|
7
|
-
TYPE = 'sc:AnnotationList'
|
|
6
|
+
TYPE = "sc:AnnotationList"
|
|
8
7
|
|
|
9
8
|
def required_keys
|
|
10
|
-
super + %w
|
|
9
|
+
super + %w[@id]
|
|
11
10
|
end
|
|
12
11
|
|
|
13
|
-
def array_only_keys
|
|
14
|
-
super + %w
|
|
12
|
+
def array_only_keys
|
|
13
|
+
super + %w[resources]
|
|
15
14
|
end
|
|
16
15
|
|
|
17
|
-
def initialize(hsh={})
|
|
18
|
-
hsh[
|
|
19
|
-
super
|
|
16
|
+
def initialize(hsh = {})
|
|
17
|
+
hsh["@type"] = TYPE unless hsh.has_key? "@type"
|
|
18
|
+
super
|
|
20
19
|
end
|
|
21
20
|
|
|
22
21
|
def validate
|
|
23
22
|
# Each member or resources must be a kind of Annotation
|
|
24
23
|
end
|
|
25
|
-
|
|
26
24
|
end
|
|
27
25
|
end
|
|
28
26
|
end
|