Class: WorldTopMovies::DB::User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- WorldTopMovies::DB::User
- Defined in:
- lib/world_top_movies/models/user.rb
Instance Method Summary collapse
- #favourite_movie_titles ⇒ Object
- #find_movie_from_url(movie_url) ⇒ Object
- #find_note_from_id(note_id) ⇒ Object
- #movies_with_notes_arr ⇒ Object
- #movies_with_notes_titles ⇒ Object
- #notes_titles ⇒ Object
- #print_all_favourite_movie_titles ⇒ Object
- #print_all_notes ⇒ Object
- #print_movies_with_notes ⇒ Object
Instance Method Details
#favourite_movie_titles ⇒ Object
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_arr ⇒ Object
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_titles ⇒ Object
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_titles ⇒ Object
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 |
#print_all_favourite_movie_titles ⇒ Object
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 |
#print_all_notes ⇒ Object
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 |
#print_movies_with_notes ⇒ Object
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 |