Skip to content

Instantly share code, notes, and snippets.

@Prigin
Created October 14, 2019 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Prigin/3ae0fbd00967ccb425b62a509a7460b4 to your computer and use it in GitHub Desktop.
Save Prigin/3ae0fbd00967ccb425b62a509a7460b4 to your computer and use it in GitHub Desktop.
task 4
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){|a| a.date.split("-")}
puts
puts"========DIRECTORS========"
puts mas.collect{|unit| unit.director}.uniq.sort_by{|a| a.split(" ").last}
puts
puts"=========NOT_USA========="
puts mas.select{|unit| unit.country != "USA" }.length
puts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment