Sha256: 95a8205bd8551014e72fd5764ca48abaf87946f25e8f98f5a2f7f894ceb1ac52

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

module Riiif
  # This is the result of calling the Riiif.image_info service. It stores the height & width
  class ImageInformation
    extend Deprecation

    def initialize(width, height)
      @width = width
      @height = height
    end

    attr_reader :width, :height

    def to_h
      { width: width, height: height }
    end

    def [](key)
      to_h[key]
    end
    deprecation_deprecate :[] => 'Riiif::ImageInformation#[] has been deprecated ' \
      'and will be removed in version 2.0. Use Riiif::ImageInformation#to_h and ' \
      'call #[] on that result OR consider using #height and #width directly.'

    # Image information is only valid if height and width are present.
    # If an image info service doesn't have the value yet (not characterized perhaps?)
    # then we wouldn't want to cache this value.
    def valid?
      width.present? && height.present?
    end

    def ==(other)
      other.class == self.class &&
        other.width == width &&
        other.height == height
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
riiif-1.7.1 app/models/riiif/image_information.rb
riiif-1.7.0 app/models/riiif/image_information.rb