Last active
March 29, 2017 22:09
-
-
Save fee1good/03010630b4c8f42b74092ce655fde6af to your computer and use it in GitHub Desktop.
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
movie = ARGV[0] || 'movies.txt' | |
if !File.exist?(movie) | |
p 'File error' | |
return | |
end | |
whole_list = Array.new | |
KEYS = [:link, :title, :year, :country, :date, :genre, :duration, :rating, :director, :actors] | |
File.readlines(movie).map do |line| | |
ar_line = line.split('|') | |
list = KEYS.zip(ar_line).to_h | |
whole_list << list | |
end | |
longest_movies = whole_list.max_by(4){|i| i[:duration].to_i} | |
comedy_movies = whole_list.select{|m| m[:genre].include?("Comedy")}.sort_by{|i| i[:date]}[0..9] | |
p "Director's sorting:" | |
whole_list.map{|m| m[:director]}.uniq.sort_by{|dir| dir.split(" ").last}.each{|dir| p dir} | |
p "Number of Movies created not in USA — #{whole_list.count{|m| m[:country] != "USA"}}" | |
def parse_movies(arr) | |
arr.each{|m| p "Title: #{m[:title]}, year: #{m[:year]}, country: #{m[:country]}, genre: #{m[:genre]} and duration — #{m[:duration]}"} | |
end | |
p "Longest movies list:" | |
parse_movies(longest_movies) | |
p "Comedies:" | |
parse_movies(comedy_movies) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment