Class: OSDb::Sub

Inherits:
Object
  • Object
show all
Defined in:
lib/osdb/sub.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Sub

Returns a new instance of Sub.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/osdb/sub.rb', line 13

def initialize(data)
  @url = URI.parse(data['SubDownloadLink'])
  @format = data['SubFormat']
  @language = Language.from_iso639_2b(data['SubLanguageID'])
  @rating = data['SubRating'].to_f
  @user_ranks = data['UserRank']
  @movie_name = data['MovieName']
  @filename = data['SubFileName']
  @downloads_count = data['SubDownloadsCnt'].to_i
  @bad_reports_count = data['SubBad'].to_i
  @raw_data = data
end

Instance Attribute Details

#bad_reports_countObject (readonly)

Returns the value of attribute bad_reports_count.



10
11
12
# File 'lib/osdb/sub.rb', line 10

def bad_reports_count
  @bad_reports_count
end

#downloads_countObject (readonly)

Returns the value of attribute downloads_count.



10
11
12
# File 'lib/osdb/sub.rb', line 10

def downloads_count
  @downloads_count
end

#filenameObject (readonly)

Returns the value of attribute filename.



10
11
12
# File 'lib/osdb/sub.rb', line 10

def filename
  @filename
end

#formatObject (readonly)

Returns the value of attribute format.



10
11
12
# File 'lib/osdb/sub.rb', line 10

def format
  @format
end

#languageObject (readonly)

Returns the value of attribute language.



10
11
12
# File 'lib/osdb/sub.rb', line 10

def language
  @language
end

#movie_nameObject (readonly)

Returns the value of attribute movie_name.



10
11
12
# File 'lib/osdb/sub.rb', line 10

def movie_name
  @movie_name
end

#ratingObject (readonly)

Returns the value of attribute rating.



10
11
12
# File 'lib/osdb/sub.rb', line 10

def rating
  @rating
end

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



10
11
12
# File 'lib/osdb/sub.rb', line 10

def raw_data
  @raw_data
end

#urlObject (readonly)

Returns the value of attribute url.



10
11
12
# File 'lib/osdb/sub.rb', line 10

def url
  @url
end

#user_ranksObject (readonly)

Returns the value of attribute user_ranks.



10
11
12
# File 'lib/osdb/sub.rb', line 10

def user_ranks
  @user_ranks
end

Instance Method Details

#<=>(other) ⇒ Object



26
27
28
# File 'lib/osdb/sub.rb', line 26

def <=>(other)
  rating <=> other.rating
end

#bodyObject



41
42
43
# File 'lib/osdb/sub.rb', line 41

def body
  @body ||= fetch_body
end

#fetch_bodyObject



45
46
47
48
49
50
51
# File 'lib/osdb/sub.rb', line 45

def fetch_body
  StringIO.open do |buffer|
    buffer.write(Net::HTTP.get(url))
    buffer.rewind
    return Zlib::GzipReader.new(buffer).read
  end
end

#scoreObject

Totaly subjective formula to evaluate subtitle quality Originaly developed by runa (github.com/runa) github.com/byroot/ruby-osdb/commit/9d71775#L0R122



33
34
35
# File 'lib/osdb/sub.rb', line 33

def score
  uploader_score * downloads_count.next * (rating + 1) - bad_reports_count / downloads_count.next
end

#uploader_scoreObject



37
38
39
# File 'lib/osdb/sub.rb', line 37

def uploader_score
  user_ranks.empty? ? 1 : 2
end