Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Movie
- attr_accessor :link, :movie, :year, :country, :showing, :jenre, :length, :value, :director, :actor
- def initialize(link, movie, year, country, showing, jenre, length, value, director, actor)
- @link = link
- @movie = movie
- @year = year
- @country = country
- @showing = showing
- @jenre = jenre
- @length = length
- @value = value
- @director = director
- @actor = actor
- end
- end
- class MovieCollection
- attr_accessor :file
- def initialize(file)
- @file = file
- @movies = []
- read_file
- end
- def read_file
- File.readlines(@file).each do |line|
- params = line.split("|")
- new_movie = Movie.new(params[0], params[1], params[2], params[3],
- params[4], params[5], params[6], params[7], params[8], params[9])
- @movies.push(new_movie)
- end
- end
- def all
- @movies
- end
- def sort_by(year)
- @movies.sort_by{|movie| movie.send(year)}
- end
- def filter(jenre)
- field = jenre.keys.first
- value = jenre[key]
- @movies.select { |movie| movie.send[field].include?(value) }
- end
- end
- collection = MovieCollection.new("movies.txt")
- p collection.filter(jenre: 'Comedy')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement