Skip to content

Instantly share code, notes, and snippets.

@Prigin
Created October 9, 2019 18:30
Show Gist options
  • Save Prigin/b87350475cc86df40fab95863b095186 to your computer and use it in GitHub Desktop.
Save Prigin/b87350475cc86df40fab95863b095186 to your computer and use it in GitHub Desktop.
MKDEV
mas = []
doc = "movies.txt"
syms = [:link, :title, :year, :country,
:date, :genre, :duration,
:rating, :director, :stars]
File.foreach(doc){ |line|
mas.append(syms.zip(line.chomp.split("|")).to_h) }
def Show_em (mas)
mas.each do |unit|
puts unit[:title] + " (" + unit[:date] + "; " +unit[:genre] +") - " + unit[:duration]
end
end
puts
puts"=========LONGEST========="
Show_em mas.max(5){|a,b|
a[:duration].split(" ")[0].to_i<=>b[:duration].split(" ")[0].to_i}
puts
puts"====EARLIEST_COMEDIES===="
Show_em mas.select{|unit| unit[:genre].include?("Comedy")}.min(10){|a,b|
a[:date].split("-")<=>b[:date].split("-")}
puts
puts"========DIRECTORS========"
puts mas.collect{|unit| unit[:director]}.uniq.sort{|a, b|
a.split(" ")[-1]<=>b.split(" ")[-1]}
puts
puts"=========NOT_USA========="
Show_em mas.select{|unit| unit[:country] != "USA" }
puts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment