Class: Addic7ed::SubtitlesCollection

Inherits:
Array
  • Object
show all
Defined in:
lib/addic7ed/models/subtitles_collection.rb

Overview

Represents a collection of Subtitle objects.

This collection inherits from Array so it behaves exaclty like it, but it also provides some methods to filter, order and choose the best subtitle.

Instance Method Summary collapse

Instance Method Details

#compatible_with(group) ⇒ SubtitleCollection

Returns only subtitles that are compatible with group.

Examples:

fov        = Addic7ed::Subtitle.new(version: "FOV")
lol        = Addic7ed::Subtitle.new(version: "LOL")
dimension  = Addic7ed::Subtitle.new(version: "DIMENSION")
collection = Addic7ed::SubtitlesCollection.new([fov, lol, dimension])

collection.compatible_with("DIMENSION")
#=> [#<Addic7ed::Subtitle @version="LOL">, #<Addic7ed::Subtitle @version="DIMENSION">]

Parameters:

  • group (String)

    Release group we want the returned subtitles to be compatible with

Returns:

  • (SubtitleCollection)

    Copy of collection with subtitles compatible with group only


21
22
23
# File 'lib/addic7ed/models/subtitles_collection.rb', line 21

def compatible_with(group)
  select { |subtitle| CheckCompatibility.call(subtitle, group) }
end

#completedSubtitleCollection

Returns only completed subtitles.

Examples:

complete   = Addic7ed::Subtitle.new(status: "Completed")
wip        = Addic7ed::Subtitle.new(status: "50%")
collection = Addic7ed::SubtitlesCollection.new([complete, wip])

collection.completed
#=> [#<Addic7ed::Subtitle @status="Completed">]

Returns:

  • (SubtitleCollection)

    Copy of collection with completed subtitles only


37
38
39
# File 'lib/addic7ed/models/subtitles_collection.rb', line 37

def completed
  select(&:completed?)
end

Returns the most downloaded subtitle.

Examples:

popular    = Addic7ed::Subtitle.new(downloads: 1000)
unpopular  = Addic7ed::Subtitle.new(downloads: 3)
collection = Addic7ed::SubtitlesCollection.new([popular, unpopular])

collection.most_popular
#=> #<Addic7ed::Subtitle @downloads=1000>

Returns:

  • (Subtitle)

    Subtitle of the collection with the more downloads


53
54
55
# File 'lib/addic7ed/models/subtitles_collection.rb', line 53

def most_popular
  sort_by(&:downloads).last
end