Commit dd1277b6
Changed files (5)
app
services
infrastructure
spec
services
infrastructure
app/models/large_version.rb
@@ -1,9 +1,9 @@
- class LargeVersion < Version
- def initialize(photo)
- super(photo, :large, "large_")
- end
+class LargeVersion < Version
+ def initialize(photo)
+ super(photo, :large, "large_")
+ end
- def adjust(image)
- image.resize_to_fit(570, 630)
- end
+ def adjust(image)
+ image.resize_to_fit(width: 570, height: 630)
end
+end
app/models/original_version.rb
@@ -1,7 +1,7 @@
- class OriginalVersion < Version
- def initialize(photo)
- super(photo, :original, "")
- end
-
- def adjust(image); end
+class OriginalVersion < Version
+ def initialize(photo)
+ super(photo, :original, "")
end
+
+ def adjust(image); end
+end
app/models/thumbnail_version.rb
@@ -1,9 +1,9 @@
- class ThumbnailVersion < Version
- def initialize(photo)
- super(photo, :thumb, "thumb_")
- end
+class ThumbnailVersion < Version
+ def initialize(photo)
+ super(photo, :thumb, "thumb_")
+ end
- def adjust(image)
- image.resize_to_fill(260, 180)
- end
+ def adjust(image)
+ image.resize_to_fill(width: 260, height: 180)
end
+end
app/services/infrastructure/image.rb
@@ -23,7 +23,7 @@ class Image
@sha256 ||= Digest::SHA256.file(@path).to_s
end
- def resize_to_fit(width, height)
+ def resize_to_fit(width:, height:)
manipulate! do |img|
img.resize "#{width}x#{height}"
img = yield(img) if block_given?
@@ -31,7 +31,7 @@ class Image
end
end
- def resize_to_fill(width, height, gravity = 'Center')
+ def resize_to_fill(width:, height:, gravity: 'Center')
manipulate! do |img|
cols, rows = img[:dimensions]
img.combine_options do |cmd|
spec/services/infrastructure/image_spec.rb
@@ -66,15 +66,15 @@ describe Image do
end
it "resizes the image to fit" do
- subject.resize_to_fit(130, 90)
+ subject.resize_to_fit(width: 570, height: 630)
image = MiniMagick::Image.open(path)
- expect(image[:width]).to eql(130)
- expect(image[:height]).to eql(90)
+ expect(image[:width]).to eql(570)
+ expect(image[:height]).to eql(395)
end
it "resizes the image to fill" do
- subject.resize_to_fill(130, 90)
+ subject.resize_to_fill(width: 130, height: 90)
image = MiniMagick::Image.open(path)
expect(image[:width]).to eql(130)