Class: Imba::MovieList
- Inherits:
-
Object
- Object
- Imba::MovieList
- Includes:
- Colors
- Defined in:
- lib/imba/movie_list.rb
Instance Attribute Summary collapse
-
#movies ⇒ Object
readonly
Returns the value of attribute movies.
Instance Method Summary collapse
- #add ⇒ Object
-
#initialize ⇒ MovieList
constructor
A new instance of MovieList.
- #movie_dirs ⇒ Object
- #synch ⇒ Object
Methods included from Colors
Constructor Details
#initialize ⇒ MovieList
Returns a new instance of MovieList.
6 7 8 |
# File 'lib/imba/movie_list.rb', line 6 def initialize @movies = Movie.all end |
Instance Attribute Details
#movies ⇒ Object (readonly)
Returns the value of attribute movies.
4 5 6 |
# File 'lib/imba/movie_list.rb', line 4 def movies @movies end |
Instance Method Details
#add ⇒ Object
16 17 18 |
# File 'lib/imba/movie_list.rb', line 16 def add Imba::DataStore[:movies] = movie_dirs end |
#movie_dirs ⇒ Object
10 11 12 13 14 |
# File 'lib/imba/movie_list.rb', line 10 def movie_dirs # don't belong here... # get movie names (dirs) @movie_dirs ||= Dir['*'].select { |f| File.directory? f } end |
#synch ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/imba/movie_list.rb', line 21 def synch prompt = '(enter "y" to confirm or anything else to continue)' # for each movie movie_dirs.each do |directory_name| # check movie name on imdb result = Imdb::Movie.search(directory_name).first # needs rescue? movie_title = result.title.gsub(/\(\d+\)/, '').strip movie = "#{movie_title} (#{result.year}) #{result.genres} #{result.rating}/10" # puts foundings # update movie name? (folder) if directory_name != movie_title puts "change #{red(directory_name)} => #{green(movie_title)}? \n#{prompt}" FileUtils.mv(directory_name, movie_title) if STDIN.gets.strip.downcase == 'y' end if Imba::DataStore.key?(result.id) && Imba::DataStore[result.id] != movie puts "update?\n- #{red(Imba::DataStore[result.id])} \n+ #{green(movie)} \n#{prompt}" Imba::DataStore[result.id] = movie if STDIN.gets.strip.downcase == 'y' else Imba::DataStore[result.id] = movie end # ask if founding is correct # write .imdb_uniq_id in movie folder # save movie name and imdb_uniq_id in DataStore[:movies] # or serialize hole imdb movie object?! end STDOUT.puts 'done' end |