Class: WaxIiif::ImageInfo
- Inherits:
-
Object
- Object
- WaxIiif::ImageInfo
- Defined in:
- lib/wax_iiif/image_info.rb
Overview
Class ImageInfo is a data object for the JSON representation of the image.
It is designed to support the iiif.io/api/image/2.0/#image-information spec.
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#id ⇒ Object
Returns the value of attribute id.
-
#tile_scale_factors ⇒ Object
Returns the value of attribute tile_scale_factors.
-
#tile_width ⇒ Object
Returns the value of attribute tile_width.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
-
#context ⇒ String
The IIIF context for this image.
-
#initialize(uri, variants, tile_width = nil, tile_scale_factors = nil) ⇒ ImageInfo
constructor
A new instance of ImageInfo.
-
#profile ⇒ String
The IIIF profile this image supports.
-
#protocol ⇒ String
The IIIF protocol for this image.
-
#service ⇒ Object
TODO: Implement this.
-
#sizes ⇒ Hash
A collection of valid sizes based on the available image variants.
-
#tiles ⇒ Hash?
The hash of tile information, or nil if the information does not exist.
-
#to_json(*_args) ⇒ String
Generate the JSON data for this image in the IIIF-expected format.
Constructor Details
#initialize(uri, variants, tile_width = nil, tile_scale_factors = nil) ⇒ ImageInfo
Returns a new instance of ImageInfo.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/wax_iiif/image_info.rb', line 12 def initialize(uri, variants, tile_width = nil, tile_scale_factors = nil) raise WaxIiif::Error::InvalidImageData, "No full variant provided: variants: #{variants}" unless variants['full'] raise WaxIiif::Error::InvalidImageData, "No thumbnail variant provided: variants: #{variants}" unless variants['thumbnail'] raise WaxIiif::Error::InvalidImageData, 'No URI was provided for this image!' if uri.nil? @id = uri @full = variants['full'] @variants = variants @width = @full.width @height = @full.height @tile_width = tile_width @tile_scale_factors = tile_scale_factors end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
8 9 10 |
# File 'lib/wax_iiif/image_info.rb', line 8 def height @height end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/wax_iiif/image_info.rb', line 6 def id @id end |
#tile_scale_factors ⇒ Object
Returns the value of attribute tile_scale_factors.
10 11 12 |
# File 'lib/wax_iiif/image_info.rb', line 10 def tile_scale_factors @tile_scale_factors end |
#tile_width ⇒ Object
Returns the value of attribute tile_width.
9 10 11 |
# File 'lib/wax_iiif/image_info.rb', line 9 def tile_width @tile_width end |
#width ⇒ Object
Returns the value of attribute width.
7 8 9 |
# File 'lib/wax_iiif/image_info.rb', line 7 def width @width end |
Instance Method Details
#context ⇒ String
Returns The IIIF context for this image.
68 69 70 |
# File 'lib/wax_iiif/image_info.rb', line 68 def context WaxIiif::IMAGE_CONTEXT end |
#profile ⇒ String
Returns The IIIF profile this image supports.
78 79 80 81 82 |
# File 'lib/wax_iiif/image_info.rb', line 78 def profile [WaxIiif::LEVEL_0, { supports: %w[cors sizeByWhListed baseUriRedirect] }] end |
#protocol ⇒ String
Returns The IIIF protocol for this image.
73 74 75 |
# File 'lib/wax_iiif/image_info.rb', line 73 def protocol WaxIiif::IMAGE_PROTOCOL end |
#service ⇒ Object
TODO: Implement this. See <iiif.io/api/annex/services/#physical-dimensions>
85 86 87 |
# File 'lib/wax_iiif/image_info.rb', line 85 def service nil end |
#sizes ⇒ Hash
Returns a collection of valid sizes based on the available image variants.
28 29 30 31 32 |
# File 'lib/wax_iiif/image_info.rb', line 28 def sizes @variants.collect do |_name, obj| { 'width' => obj.width, 'height' => obj.height } end end |
#tiles ⇒ Hash?
The hash of tile information, or nil if the information does not exist.
38 39 40 41 42 43 44 45 |
# File 'lib/wax_iiif/image_info.rb', line 38 def tiles return nil if @tile_scale_factors.nil? || @tile_scale_factors.empty? [{ 'width' => @tile_width, 'scaleFactors' => @tile_scale_factors }] end |
#to_json(*_args) ⇒ String
Generate the JSON data for this image in the IIIF-expected format.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/wax_iiif/image_info.rb', line 51 def to_json(*_args) obj = { '@context' => context, '@id' => id, 'protocol' => protocol, 'width' => width, 'height' => height, 'sizes' => sizes, 'profile' => profile } obj['tiles'] = tiles unless tiles.nil? obj['profile'] = profile obj['service'] = service unless service.nil? JSON.pretty_generate obj end |