Class: WorldTopMovies::DB::User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/world_top_movies/models/user.rb

Instance Method Summary collapse

Instance Method Details

#favourite_movie_titlesObject



16
17
18
19
20
21
# File 'lib/world_top_movies/models/user.rb', line 16

def favourite_movie_titles
  # Returns a hash with key=title, value=url of all fav movies
  result = {}
  self.movies.sort_by { |m| m.title }.each { |m| result[m.title] = m.url }
  result
end

#find_movie_from_url(movie_url) ⇒ Object



23
24
25
# File 'lib/world_top_movies/models/user.rb', line 23

def find_movie_from_url(movie_url)
  self.movies.find { |m| m.url == movie_url }
end

#find_note_from_id(note_id) ⇒ Object



64
65
66
# File 'lib/world_top_movies/models/user.rb', line 64

def find_note_from_id(note_id)
  self.notes.find { |n| n.id == note_id }
end

#movies_with_notes_arrObject



42
43
44
# File 'lib/world_top_movies/models/user.rb', line 42

def movies_with_notes_arr
  self.notes.map { |note| note.movie }.uniq
end

#movies_with_notes_titlesObject



36
37
38
39
40
# File 'lib/world_top_movies/models/user.rb', line 36

def movies_with_notes_titles
  result = {}
  self.movies_with_notes_arr.sort_by { |m| m.title }.each { |m| result[m.title] = m.url }
  result
end

#notes_titlesObject



58
59
60
61
62
# File 'lib/world_top_movies/models/user.rb', line 58

def notes_titles
  result = {}
  self.notes.each { |n| result["#{n.note_message}, #{n.movie.title}, #{n.created_at.localtime.to_s}"] = n.id }
  result
end


7
8
9
10
11
12
13
14
# File 'lib/world_top_movies/models/user.rb', line 7

def print_all_favourite_movie_titles
  puts "\nOk! Your favourite movies are:\n\n"
  sleep(1.5)
  self.movies.sort_by { |m| m.title }.each_with_index do |m, i|
    sleep(0.01)
    WorldTopMovies::Movie.print_movie_compact(m, i)
  end
end


46
47
48
49
50
51
52
53
54
55
56
# File 'lib/world_top_movies/models/user.rb', line 46

def print_all_notes
  puts "\nPrinting #{self.notes.count} note(s):\n\n"
  sleep(1.5)
  self.notes.each_with_index do |n, i|
    sleep(0.01)
    puts "--------------------------------------------------------------"
    puts "\n#{i + 1}. #{n.note_message.colorize(:color => :green).italic}, \
Movie: #{n.movie.title.colorize(:color => :light_blue).bold}, \
Date: #{n.created_at.localtime.to_s.colorize(:color => :red).bold} \n"
  end
end


27
28
29
30
31
32
33
34
# File 'lib/world_top_movies/models/user.rb', line 27

def print_movies_with_notes
  puts "\nOk! Your movies with notes are:\n\n"
  sleep(1.5)
  self.movies_with_notes_arr.sort_by { |m| m.title }.each_with_index do |m, i|
    sleep(0.01)
    WorldTopMovies::Movie.print_movie_compact(m, i)
  end
end