Last active
October 15, 2019 15:56
-
-
Save Prigin/607b5608e61f981bcfcd346fb0ea96e7 to your computer and use it in GitHub Desktop.
task 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
require 'ostruct' | |
doc = "movies.txt" | |
syms = [:link, :title, :year, :country, | |
:date, :genre, :duration, | |
:rating, :director, :stars] | |
mas = CSV.readlines(doc, headers: syms, col_sep: "|").map{|unit| OpenStruct.new(unit.to_h)} | |
def Show_em (array_hash) | |
array_hash.each do |unit| | |
puts unit.title + " (" + unit.date + "; " + unit.genre + ") - " + unit.duration | |
end | |
end | |
puts | |
puts"=========LONGEST=========" | |
Show_em mas.max_by(5){|a| a.duration.split(" ").first.to_i} | |
puts | |
puts"====EARLIEST_COMEDIES====" | |
Show_em mas.select{|unit| unit.genre.include?("Comedy")}.min_by(10, &:date) | |
puts | |
puts"========DIRECTORS========" | |
puts mas.collect(&:director).uniq.sort_by{|a| a.split(" ").last} | |
puts | |
puts"=========NOT_USA=========" | |
puts mas.collect(&:country).count{|unit| unit != "USA"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment