Skip to content

Commit

Permalink
Move Client#resize_to_pixel_size to Image#resize_images
Browse files Browse the repository at this point in the history
  • Loading branch information
dtan4 committed May 29, 2014
1 parent 88eded9 commit 8bdcf9c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
10 changes: 2 additions & 8 deletions lib/photomosaic/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def execute
@image_downloader = Photomosaic::ImageDownloader.new

begin
resize_to_pixel_size(pixel_images)
Photomosaic::Image.create_mosaic_image(pixel_images, @options.output_path)
resized_images = Photomosaic::Image.resize_images(pixel_images, 40, 20)
Photomosaic::Image.create_mosaic_image(resized_images, @options.output_path)
ensure
@image_downloader.remove_save_dir
end
Expand Down Expand Up @@ -54,12 +54,6 @@ def pixel_images
base_image.dispatch_images(image_list, 1, 2, @options.color_model)
end

def resize_to_pixel_size(images)
images.map! do |row|
row.map { |image| image.resize!(40, 20, false) }
end
end

def search_engine
@options.search_engine.new(@options.api_key, @options.results)
end
Expand Down
6 changes: 6 additions & 0 deletions lib/photomosaic/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ def self.preprocess_image(image_path, width, height, level, colors)
image
end

def self.resize_images(images, width, height)
images.map do |row|
row.map { |image| image.resize!(width, height, false) }
end
end

def initialize(image_path)
@image = Magick::Image.read(image_path).first
end
Expand Down
6 changes: 3 additions & 3 deletions spec/photomosaic/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ module Photomosaic

describe "#execute" do
before do
allow_any_instance_of(described_class).to receive(:pixel_images)
allow_any_instance_of(described_class).to receive(:resize_to_pixel_size).and_return(true)
allow(Photomosaic::Image).to receive(:create_mosaic_image).and_return(true)
allow_any_instance_of(described_class).to receive(:pixel_images).and_return([[]])
allow(Photomosaic::Image).to receive(:resize_to_pixel_size)
allow(Photomosaic::Image).to receive(:create_mosaic_image)
end

it "should execute the program" do
Expand Down
18 changes: 18 additions & 0 deletions spec/photomosaic/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ module Photomosaic
described_class.preprocess_image(image_path, 100, 100, 4, 8)
end
end

describe "#resize_images" do
let(:image) do
double(:resize!)
end

let(:image_list) do
5.times.inject([]) do |image_list, _|
image_list << [image]
image_list
end
end

it "should resize images" do
expect(image).to receive(:resize!).exactly(5).times
described_class.resize_images(image_list, 40, 20)
end
end
end

context "instance methods" do
Expand Down

0 comments on commit 8bdcf9c

Please sign in to comment.