Skip to content

Instantly share code, notes, and snippets.

@Prigin
Created November 12, 2019 11:45
Show Gist options
  • Save Prigin/9f79cec047f5915dd170d169ab36a624 to your computer and use it in GitHub Desktop.
Save Prigin/9f79cec047f5915dd170d169ab36a624 to your computer and use it in GitHub Desktop.
mkdev
require_relative 'movie_coll.rb'
def compare (val_mov, film_val)
if val_mov.is_a?(Array)
val_mov.any?(film_val)
else
film_val === val_mov
end
end
def filter(**filters)
filters.each_key{|key|
raise "<filter> wrong parameter #{key.inspect}" unless @mas[0].respond_to?(key)}
buff = @mas.select do |movie|
filters.inject(true) do |bool, hash_val|
mov = movie.send(hash_val[0])
if mov.is_a?(Array)
bool & ( mov.any?(hash_val[1]) )
else
bool & ( hash_val[1] === mov )
end
end
end
return "no matches" if buff.empty?
buff
end
@mas = MovieCollection.new("movies_v2.txt").all
puts filter(genre: "Drama", country: "France")
.map{|u| "#{u.title} #{u.genre} #{u.duration} min(s) #{u.country}"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment