class Photomosaic::Client

Public Class Methods

new(argv) click to toggle source
# File lib/photomosaic/client.rb, line 3
def initialize(argv)
  @options = Photomosaic::Options.parse(argv)
end

Public Instance Methods

execute() click to toggle source
# File lib/photomosaic/client.rb, line 7
def execute
  @image_downloader = Photomosaic::ImageDownloader.new

  begin
    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
end

Private Instance Methods

base_image() click to toggle source
# File lib/photomosaic/client.rb, line 20
def base_image
  @base_image ||= Photomosaic::Image.preprocess_image(
                                                      @options.base_image,
                                                      @options.width,
                                                      @options.height,
                                                      @options.level,
                                                      @options.colors
                                                     )
end
image_list() click to toggle source
# File lib/photomosaic/client.rb, line 38
def image_list
  @image_list ||= image_path_list.map do |path|
    begin
      Photomosaic::Image.new(path)
    rescue Magick::ImageMagickError
      nil
    end
  end.compact
end
image_path_list() click to toggle source
# File lib/photomosaic/client.rb, line 30
def image_path_list
  @image_path_list ||= @image_downloader.download_images(image_url_list)
end
image_url_list() click to toggle source
# File lib/photomosaic/client.rb, line 34
def image_url_list
  @image_url_list ||= search_engine.get_image_list(@options.keyword)
end
pixel_images() click to toggle source
# File lib/photomosaic/client.rb, line 48
def pixel_images
  @pixel_images ||=
    base_image.dispatch_images(image_list, 1, 2, @options.color_model)
end
search_engine() click to toggle source
# File lib/photomosaic/client.rb, line 53
def search_engine
  @options.search_engine.new(@options.api_key, @options.results)
end