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(options = {}) ⇒ Subtitle

Returns a new instance of Subtitle.



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

def initialize(options = {})
  @version   = Addic7edVersionNormalizer.call(options[:version])
  @language  = options[:language]
  @status    = options[:status]
  @url       = options[:url]
  @via       = options[:via]
  @hi        = options[:hi]
  @downloads = options[:downloads].to_i || 0
  @comment   = Addic7edCommentNormalizer.call(options[:comment])
end

Instance Attribute Details

#commentObject (readonly)

Returns the value of attribute comment.



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

def comment
  @comment
end

#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_subtitle) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
# File 'lib/addic7ed/subtitle.rb', line 27

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

#is_completed?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/addic7ed/subtitle.rb', line 39

def is_completed?
  status == 'Completed'
end

#is_featured?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/addic7ed/subtitle.rb', line 35

def is_featured?
  via == "http://addic7ed.com"
end

#to_sObject



18
19
20
# File 'lib/addic7ed/subtitle.rb', line 18

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

#works_for?(version = '', no_hi = false) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
# File 'lib/addic7ed/subtitle.rb', line 22

def works_for?(version = '', no_hi = false)
  hi_works = !@hi || !no_hi
  is_completed? and is_compatible_with? version and hi_works
end