Created
October 2, 2020 03:27
-
-
Save renatodex/1dd3b00c77fc0ccb0b9f6809cf1d0561 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
class UnpublishMovies | |
def call | |
movies_to_unpublish = Movies.where_not( | |
unpublish_at: nil, | |
) | |
series_to_unpublish = Series.where_not( | |
unpublish_at: nil, | |
) | |
shows_to_unpublish = Shows.where_not( | |
unpublish_at: nil, | |
) | |
unpublish_non_podcasts([ | |
movies_to_unpublish, | |
series_to_unpublish, | |
shows_to_unpublish, | |
]) | |
unpublish_podcasts( | |
podcasts_to_unpublish, | |
) | |
end | |
def podcasts_to_unpublish | |
podcasts = Podcasts.all | |
podcasts.filter do |podcast| | |
parse_bizarre_time(*podcast.date_to_unpublish_podcast) <= Time.now | |
end | |
end | |
def unpublish_podcasts(podcasts) | |
podcasts.each(&:unpublish_from_catalog) | |
end | |
def unpublish_non_podcasts(non_podcasts) | |
non_podcasts.each do |non_podcast| | |
if non_podcast.unpublish_at <= Time.now | |
non_podcast.unpublish_from_catalog! | |
end | |
end | |
end | |
def parse_bizarre_time(year, month, day, hour, minute, second) | |
Time.parse("#{year}-#{month}-#{day} #{hour}:#{minute}:#{second}") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment