Class: Addic7ed::Subtitle

Inherits:
Object
  • Object
show all
Defined in:
lib/addic7ed/subtitle.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version, language, status, url, via, downloads) ⇒ Subtitle

Returns a new instance of Subtitle.



7
8
9
10
11
12
13
14
# File 'lib/addic7ed/subtitle.rb', line 7

def initialize(version, language, status, url, via, downloads)
  @version   = normalized_version(version)
  @language  = language
  @status    = status
  @url       = url
  @via       = via
  @downloads = downloads.to_i
end

Instance Attribute Details

#downloadsObject (readonly)

Returns the value of attribute downloads.



4
5
6
# File 'lib/addic7ed/subtitle.rb', line 4

def downloads
  @downloads
end

#languageObject (readonly)

Returns the value of attribute language.



4
5
6
# File 'lib/addic7ed/subtitle.rb', line 4

def language
  @language
end

#statusObject (readonly)

Returns the value of attribute status.



4
5
6
# File 'lib/addic7ed/subtitle.rb', line 4

def status
  @status
end

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/addic7ed/subtitle.rb', line 5

def url
  @url
end

#versionObject (readonly)

Returns the value of attribute version.



4
5
6
# File 'lib/addic7ed/subtitle.rb', line 4

def version
  @version
end

#viaObject (readonly)

Returns the value of attribute via.



4
5
6
# File 'lib/addic7ed/subtitle.rb', line 4

def via
  @via
end

Instance Method Details

#can_replace?(other_sub) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
# File 'lib/addic7ed/subtitle.rb', line 24

def can_replace?(other_sub)
  return false unless is_completed?
  return true if other_sub.nil?
  language == other_sub.language and
  is_compatible_with? other_sub.version and
  is_more_popular_than? other_sub
end

#to_sObject



16
17
18
# File 'lib/addic7ed/subtitle.rb', line 16

def to_s
  "#{url}\t->\t#{@version} (#{language}, #{status}) [#{@downloads} downloads]#{" (via #{via})" if @via}"
end

#works_for?(version = '') ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/addic7ed/subtitle.rb', line 20

def works_for?(version = '')
  is_completed? and is_compatible_with? version
end