Last active
April 3, 2017 22:09
-
-
Save fee1good/c671405c59a64886d4b65c5bf9745b00 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
require 'csv' | |
require 'ostruct' | |
require 'date' | |
arr = CSV.open("movies1.txt", {:col_sep => "|"}).map{|row| OpenStruct.new(:link => row[0], :title => row[1], :year => row[2], :country => row[3], :date => row[4], :genre => row[5], :duration => row[6], :rating => row[7], :director => row[8], :actors => row[9])} | |
arr.max_by(5){|i| i.duration.to_i}.each{|i| p i.title} | |
arr.select{|i| i.genre.include?("Comedy")}.each{|i| p i.title}[0..9] | |
arr.map{|m| m.director}.uniq.sort_by{|dir| dir.split(" ").last}.each{|dir| p dir} | |
p arr.count{|m| m.country != "USA"} | |
dates = arr.each do |i| | |
if i.date.length < 10 | |
i.date << '-01' | |
end | |
end | |
dates_updated = dates.map{|d| Date.parse(d.date)} | |
dates_updates_sorted = dates_updated.sort_by{|i| i.mon}.each{|i| i} | |
hash_sorted = {} | |
dates_updates_sorted.each do |i| | |
hash_sorted[i.mon] = arr.select{|d| d.date.eql?(i.to_s)} | |
end | |
hash_sorted.each_key do |m| | |
p "In #{Date::MONTHNAMES[m]} these movies have been released - #{hash_sorted[m][0].title}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment