Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions test/exercise/fp/solution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,27 @@ 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
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

def rated_and_multi_country?(film)
film['rating_kinopoisk'].to_f.positive? &&
film['country'].to_s.split(',').size > 1
end
end
end
Expand Down
2 changes: 0 additions & 2 deletions test/exercise/fp/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -18,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)
Expand Down