Created
March 2, 2018 12:06
-
-
Save Nursultan91/c7815faf4dc61784323a2ceb92a9b207 to your computer and use it in GitHub Desktop.
Вот весь код касающийся этого задания
This file contains hidden or 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' | |
filename = ARGV.first || 'movies.txt' | |
abort("Файл не найден") unless File.exist?(filename) | |
FIELDS = %i[link title year country premiere genre duration rank director cast] | |
ostruct_movie_arr = CSV.foreach(filename, col_sep: '|', headers: FIELDS ) | |
.map { |line| OpenStruct.new(line.to_h) } | |
month_hash = { "1" => 0, "2" => 0, "3" => 0, "4" => 0, "5" => 0, "6" => 0, "7" => 0, "8" => 0, "9" => 0, "10" => 0, "11" => 0, "12" => 0} | |
month_array = ostruct_movie_arr.reject{ |movie| movie.premiere.length <= 5 } | |
.map{|movie| Date.strptime(movie.premiere, '%Y-%m').mon} | |
uniq_month_array = month_array.uniq | |
month_array.each do |month| | |
month_hash[month] +=1 | |
end | |
puts month_hash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment