Skip to content

Commit

Permalink
Cast height and width to integers. Fixes #96
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Sep 8, 2017
1 parent 9efd1a2 commit 2f0d426
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
13 changes: 9 additions & 4 deletions app/services/riiif/region/absolute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ module Region
class Absolute < Crop
# TODO: only kakadu needs image_info. So there's potenial to optimize by
# making image_info a proxy that fetches the info lazily when needed.
# @param [ImageInformation] image_info
# @param [String] x
# @param [String] y
# @param [String] width
# @param [String] height
def initialize(image_info, x, y, width, height)
@image_info = image_info
@offset_x = x
@offset_y = y
@width = width
@height = height
@offset_x = x.to_i
@offset_y = y.to_i
@width = width.to_i
@height = height.to_i
end

attr_reader :width, :height
Expand Down
7 changes: 5 additions & 2 deletions app/services/riiif/size/absolute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ module Size
# The aspect ratio of the returned image may be different than the extracted
# region, resulting in a distorted image.
class Absolute < Resize
# @param [ImageInformation] info
# @param [String] width
# @param [String] height
def initialize(info, width, height)
@image_info = info
@width = width
@height = height
@width = width.to_i
@height = height.to_i
end

# @return [String] a resize directive for imagemagick to use
Expand Down
17 changes: 17 additions & 0 deletions spec/services/riiif/region/absolute_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'

RSpec.describe Riiif::Region::Absolute do
let(:image_info) { double }

context 'when initialized with strings' do
let(:instance) { described_class.new(image_info, '5', '15', '50', '100') }

it 'casts height to an integer' do
expect(instance.height).to eq 100
end

it 'casts width to an integer' do
expect(instance.width).to eq 50
end
end
end
17 changes: 17 additions & 0 deletions spec/services/riiif/size/absolute_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'

RSpec.describe Riiif::Size::Absolute do
let(:image_info) { double }

context 'when initialized with strings' do
let(:instance) { described_class.new(image_info, '50', '100') }

it 'casts height to an integer' do
expect(instance.height).to eq 100
end

it 'casts width to an integer' do
expect(instance.width).to eq 50
end
end
end

0 comments on commit 2f0d426

Please sign in to comment.