Skip to content

Instantly share code, notes, and snippets.

@Nursultan91
Created March 2, 2018 12:06
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 Nursultan91/c7815faf4dc61784323a2ceb92a9b207 to your computer and use it in GitHub Desktop.
Save Nursultan91/c7815faf4dc61784323a2ceb92a9b207 to your computer and use it in GitHub Desktop.
Вот весь код касающийся этого задания
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