Sha256: 5e107201c595aeff659685ac6c1b309ec1dab32b70934836d616562ca8e4f43e
Contents?: true
Size: 1.46 KB
Versions: 1
Compression:
Stored size: 1.46 KB
Contents
require 'lib/imdb' require 'src/model' module Controller def self.process_info(imdb, options = {}) if options[:offline] unless options[:next] return Movie.get_list(options) else return Movie.next end else movies = [] unless options[:next] res = imdb.get_list(options) { |step, max, text| yield(step, max, text) if block_given? } else res = imdb.next { |step, max, text| yield(step, max, text) if block_given? } end i = 0 res.sort{|x,y| x[0] <=> y[0]}.each do |k,v| if block_given? yield(i, res.size, 'Downloading movie posters') i = i + 1 end record = Movie.find(:first, :conditions => "code = '#{v[:code]}'") if record.nil? record = Movie.new(v) options[:path] ||= "#{$GIMDB_PATH}/posters/" image_path = "#{options[:path]}#{record.code}.jpg" if imdb.get_image(record.image_url, image_path) record.image_path = image_path end record.save! else imdb.get_image(record.image_url, record.image_path) if !record.image_path.nil? && !File.exists?(record.image_path) if (Time.now - record.updated_at) > 1.day record.update_attributes(v.merge(:updated_at => Time.now)) record.save! end end movies << record end yield(res.size, res.size) if block_given? return movies end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gimdb-0.0.1 | src/controller.rb |