From d1120f951b6d6370922c1942b5f3453b6c6f15fe Mon Sep 17 00:00:00 2001 From: mrjoshua22 Date: Thu, 10 Jul 2025 00:27:57 +0300 Subject: [PATCH 1/2] Add solution for ::rating method --- test/exercise/fp/solution.rb | 15 +++++++++++++-- test/exercise/fp/test.rb | 1 - 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/test/exercise/fp/solution.rb b/test/exercise/fp/solution.rb index 91c40040..490898eb 100644 --- a/test/exercise/fp/solution.rb +++ b/test/exercise/fp/solution.rb @@ -4,13 +4,24 @@ class << self # Обратиться к параметрам фильма можно так: # film["name"], film["rating_kinopoisk"], film["rating_imdb"], # film["genres"], film["year"], film["access_level"], film["country"] - def rating(_array) - 0 + def rating(array) + ratings_list = + array.map { |film| film['rating_kinopoisk'].to_f if rated_and_multi_country?(film) } + .compact + + ratings_list.reduce(&:+) / ratings_list.size end def chars_count(_films, _threshold) 0 end + + private + + def rated_and_multi_country?(film) + film['rating_kinopoisk'].to_f.positive? && + film['country'].to_s.split(',').size > 1 + end end end end diff --git a/test/exercise/fp/test.rb b/test/exercise/fp/test.rb index c1554768..d60330cf 100644 --- a/test/exercise/fp/test.rb +++ b/test/exercise/fp/test.rb @@ -7,7 +7,6 @@ class Exercise::FpTest < Minitest::Test # Посчитать средний рейтинг фильмов по версии кинопоиска у которых две или больше стран # Фильмы у которых рейтиг не задан или равен 0 не учитывать в расчете среднего. def test_rating - skip array = CSV.readlines('./test/fixtures/films.csv', headers: true) result = Exercise::Fp.rating(array) From 62134f77b57f0e1c7caeedfe1e0165c3a62fb8d4 Mon Sep 17 00:00:00 2001 From: mrjoshua22 Date: Thu, 10 Jul 2025 00:38:20 +0300 Subject: [PATCH 2/2] Add solution for ::chars_count method --- test/exercise/fp/solution.rb | 8 ++++++-- test/exercise/fp/test.rb | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/test/exercise/fp/solution.rb b/test/exercise/fp/solution.rb index 490898eb..119ca274 100644 --- a/test/exercise/fp/solution.rb +++ b/test/exercise/fp/solution.rb @@ -12,8 +12,12 @@ def rating(array) ratings_list.reduce(&:+) / ratings_list.size end - def chars_count(_films, _threshold) - 0 + def chars_count(films, threshold) + films_names = + films.map { |film| film['name'] if film['rating_kinopoisk'].to_f >= threshold } + .compact + + films_names.reduce(0) { |total, name| total + name.count('и') } end private diff --git a/test/exercise/fp/test.rb b/test/exercise/fp/test.rb index d60330cf..bcdb360e 100644 --- a/test/exercise/fp/test.rb +++ b/test/exercise/fp/test.rb @@ -17,7 +17,6 @@ def test_rating # Посчитать количесвто букв 'и' в названиях всех фильмов с рейтингом кинопоиска больше или равным заданному значению def test_chars_count - skip array = CSV.readlines('./test/fixtures/films.csv', headers: true) result = Exercise::Fp.chars_count(array, 5)