<commit_before>#!/usr/bin/env ruby

if ARGV.empty?
  puts "There are no arguments!"
  exit
end

path = ARGV.shift

if File.exist?(path)
  movies = File.open(path)
else
  puts "File not found: #{path}"
  exit
end

hash = Hash.new {|key, value| key[value]={}} 

movies.readlines.each do |movie|
  movie.chomp!
  link, name, year, country, date, genre, duration, rating, director, actors = movie.split("|")
  hash[name] = { link: link, year: year, country: country, date: date, genre: genre, duration: duration, rating: rating, director: director, actors: actors }
end   

puts "5 longest movies"
puts hash.sort_by { |k, v| v[:duration].gsub!(/ min/, '').to_i }.last(5)

puts "\nComedy sorted by release date"
puts hash.select { |k, v| v[:genre].include? "Comedy" }.sort_by {|k, v| v[:date] }

puts "\nDirector list: "
puts hash.map { |k, v| v[:director] }.to_a.sort.uniq

puts "\nCount not USA films"
puts hash.reject { |k, v| v[:country] == "USA" }.count<commit_msg>Display the count of movies grouped by director<commit_after>#!/usr/bin/env ruby

if ARGV.empty?
  puts "There are no arguments!"
  exit
end

path = ARGV.shift

if File.exist?(path)
  movies = File.open(path)
else
  puts "File not found: #{path}"
  exit
end

hash = Hash.new {|key, value| key[value]={}} 

movies.readlines.each do |movie|
  movie.chomp!
  link, name, year, country, date, genre, duration, rating, director, actors = movie.split("|")
  hash[name] = { link: link, year: year, country: country, date: date, genre: genre, duration: duration, rating: rating, director: director, actors: actors }
end   

puts "5 longest movies"
puts hash.sort_by { |k, v| v[:duration].gsub!(/ min/, '').to_i }.last(5)

puts "\nComedy sorted by release date"
puts hash.select { |k, v| v[:genre].include? "Comedy" }.sort_by {|k, v| v[:date] }

puts "\nDirector list: "
puts hash.map { |k, v| v[:director] }.to_a.sort.uniq

puts "\nCount not USA films"
puts hash.reject { |k, v| v[:country] == "USA" }.count

puts "\nCount films grouped by director"
puts hash.group_by { |x, y| y[:director] }.map { |k, v| [k, v.count] }.sort
{'fraction_non_alphanumeric': 0.17146974063400577, 'fraction_numerical': 0.0019212295869356388, 'mean_word_length': 4.14320987654321, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1813455', 'n_tokens_mistral': 802, 'n_tokens_neox': 790, 'n_words': 251}