class Addic7ed::Subtitle
Attributes
comment[R]
downloads[R]
language[R]
status[R]
url[RW]
version[R]
via[R]
Public Class Methods
new(options = {})
click to toggle source
# 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
Public Instance Methods
can_replace?(other_subtitle)
click to toggle source
# 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?()
click to toggle source
# File lib/addic7ed/subtitle.rb, line 39 def is_completed? status == 'Completed' end
is_featured?()
click to toggle source
# File lib/addic7ed/subtitle.rb, line 35 def is_featured? via == "http://addic7ed.com" end
to_s()
click to toggle source
# 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)
click to toggle source
# 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
Protected Instance Methods
commented_as_compatible_with?(other_version)
click to toggle source
# File lib/addic7ed/subtitle.rb, line 57 def commented_as_compatible_with?(other_version) return false if /(won't|doesn't|not) +work/i.match comment return false if /resync +(from|of)/i.match comment res = comment.include? other_version.downcase res ||= comment.include? COMPATIBILITY_720P[other_version].downcase if COMPATIBILITY_720P[other_version] res ||= comment.include? COMPATIBILITY_720P[version].downcase if COMPATIBILITY_720P[version] !!res end
defined_as_compatible_with(other_version)
click to toggle source
# File lib/addic7ed/subtitle.rb, line 49 def defined_as_compatible_with(other_version) version.split(",").include? other_version end
generally_compatible_with?(other_version)
click to toggle source
# File lib/addic7ed/subtitle.rb, line 53 def generally_compatible_with?(other_version) COMPATIBILITY_720P[version] == other_version || COMPATIBILITY_720P[other_version] == version end
is_compatible_with?(other_version)
click to toggle source
# File lib/addic7ed/subtitle.rb, line 45 def is_compatible_with?(other_version) defined_as_compatible_with(other_version) || generally_compatible_with?(other_version) || commented_as_compatible_with?(other_version) end
is_more_popular_than?(other_subtitle)
click to toggle source
# File lib/addic7ed/subtitle.rb, line 66 def is_more_popular_than?(other_subtitle) return true if other_subtitle.nil? return false if other_subtitle.is_featured? return downloads > other_subtitle.downloads end