Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. class Movie
  2. attr_accessor :link, :movie, :year, :country, :showing, :jenre, :length, :value, :director, :actor
  3.  
  4. def initialize(link, movie, year, country, showing, jenre, length, value, director, actor)
  5. @link = link
  6. @movie = movie
  7. @year = year
  8. @country = country
  9. @showing = showing
  10. @jenre = jenre
  11. @length = length
  12. @value = value
  13. @director = director
  14. @actor = actor
  15. end
  16. end
  17.  
  18. class MovieCollection
  19. attr_accessor :file
  20.  
  21. def initialize(file)
  22. @file = file
  23. @movies = []
  24. read_file
  25. end
  26.  
  27. def read_file
  28. File.readlines(@file).each do |line|
  29. params = line.split("|")
  30. new_movie = Movie.new(params[0], params[1], params[2], params[3],
  31. params[4], params[5], params[6], params[7], params[8], params[9])
  32. @movies.push(new_movie)
  33. end
  34. end
  35.  
  36. def all
  37. @movies
  38. end
  39.  
  40. def sort_by(year)
  41. @movies.sort_by{|movie| movie.send(year)}
  42. end
  43.  
  44. def filter(jenre)
  45. field = jenre.keys.first
  46. value = jenre[key]
  47. @movies.select { |movie| movie.send[field].include?(value) }
  48. end
  49. end
  50.  
  51. collection = MovieCollection.new("movies.txt")
  52. p collection.filter(jenre: 'Comedy')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement