class WordsToImage::Processor
Attributes
result_path[R]
words[R]
Public Class Methods
new(local_settings={})
click to toggle source
# File lib/words_to_image/processor.rb, line 7 def initialize(local_settings={}) @images_count = (local_settings[:images_count] || DEFAULT_SETTINGS[:images_count]).to_i @dictionary_path = local_settings[:dictionary_path] || DEFAULT_SETTINGS[:dictionary_path] @result_path = local_settings[:result_path] || DEFAULT_SETTINGS[:result_path] @max_row_width = [(local_settings[:max_row_width] || DEFAULT_SETTINGS[:max_row_width]).to_i, 150].max @images, @words = [], [] @dictionary = Dictionary.new(@dictionary_path) end
Public Instance Methods
create_collage()
click to toggle source
# File lib/words_to_image/processor.rb, line 28 def create_collage @result = Collage.new(@result_path, @max_row_width, @images.count) @images.each do |path| image = Image.new(path).download.squarize! @result += image image.delete! end end
get_images(keywords=[])
click to toggle source
# File lib/words_to_image/processor.rb, line 17 def get_images(keywords=[]) while !collection_complete? keyword = keywords.shift || @dictionary.get_word raise ArgumentError, "not enough words to complete a collage" unless keyword next unless image = Flickr.fetch( keyword ) @images << image @words << keyword end end
Private Instance Methods
collection_complete?()
click to toggle source
# File lib/words_to_image/processor.rb, line 39 def collection_complete? @images.count == @images_count end