Class: Imba::MovieList

Inherits:
Object
  • Object
show all
Includes:
Colors
Defined in:
lib/imba/movie_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Colors

#colorize

Constructor Details

#initializeMovieList

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

#moviesObject (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

#addObject



16
17
18
# File 'lib/imba/movie_list.rb', line 16

def add
  Imba::DataStore[:movies] = movie_dirs
end

#movie_dirsObject



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

#synchObject



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