Class: OSDb::Sub
- Inherits:
-
Object
- Object
- OSDb::Sub
- Defined in:
- lib/osdb/sub.rb
Instance Attribute Summary collapse
-
#bad_reports_count ⇒ Object
readonly
Returns the value of attribute bad_reports_count.
-
#downloads_count ⇒ Object
readonly
Returns the value of attribute downloads_count.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#movie_name ⇒ Object
readonly
Returns the value of attribute movie_name.
-
#rating ⇒ Object
readonly
Returns the value of attribute rating.
-
#raw_data ⇒ Object
readonly
Returns the value of attribute raw_data.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#user_ranks ⇒ Object
readonly
Returns the value of attribute user_ranks.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #body ⇒ Object
- #fetch_body ⇒ Object
-
#initialize(data) ⇒ Sub
constructor
A new instance of Sub.
-
#score ⇒ Object
Totaly subjective formula to evaluate subtitle quality Originaly developed by runa (github.com/runa) github.com/byroot/ruby-osdb/commit/9d71775#L0R122.
- #uploader_score ⇒ Object
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_count ⇒ Object (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_count ⇒ Object (readonly)
Returns the value of attribute downloads_count.
10 11 12 |
# File 'lib/osdb/sub.rb', line 10 def downloads_count @downloads_count end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
10 11 12 |
# File 'lib/osdb/sub.rb', line 10 def filename @filename end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
10 11 12 |
# File 'lib/osdb/sub.rb', line 10 def format @format end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
10 11 12 |
# File 'lib/osdb/sub.rb', line 10 def language @language end |
#movie_name ⇒ Object (readonly)
Returns the value of attribute movie_name.
10 11 12 |
# File 'lib/osdb/sub.rb', line 10 def movie_name @movie_name end |
#rating ⇒ Object (readonly)
Returns the value of attribute rating.
10 11 12 |
# File 'lib/osdb/sub.rb', line 10 def @rating end |
#raw_data ⇒ Object (readonly)
Returns the value of attribute raw_data.
10 11 12 |
# File 'lib/osdb/sub.rb', line 10 def raw_data @raw_data end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
10 11 12 |
# File 'lib/osdb/sub.rb', line 10 def url @url end |
#user_ranks ⇒ Object (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) <=> other. end |
#body ⇒ Object
41 42 43 |
# File 'lib/osdb/sub.rb', line 41 def body @body ||= fetch_body end |
#fetch_body ⇒ Object
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 |
#score ⇒ Object
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 * ( + 1) - bad_reports_count / downloads_count.next end |
#uploader_score ⇒ Object
37 38 39 |
# File 'lib/osdb/sub.rb', line 37 def uploader_score user_ranks.empty? ? 1 : 2 end |