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.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/osdb/sub.rb', line 10

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.



7
8
9
# File 'lib/osdb/sub.rb', line 7

def bad_reports_count
  @bad_reports_count
end

#downloads_countObject (readonly)

Returns the value of attribute downloads_count.



7
8
9
# File 'lib/osdb/sub.rb', line 7

def downloads_count
  @downloads_count
end

#filenameObject (readonly)

Returns the value of attribute filename.



7
8
9
# File 'lib/osdb/sub.rb', line 7

def filename
  @filename
end

#formatObject (readonly)

Returns the value of attribute format.



7
8
9
# File 'lib/osdb/sub.rb', line 7

def format
  @format
end

#languageObject (readonly)

Returns the value of attribute language.



7
8
9
# File 'lib/osdb/sub.rb', line 7

def language
  @language
end

#movie_nameObject (readonly)

Returns the value of attribute movie_name.



7
8
9
# File 'lib/osdb/sub.rb', line 7

def movie_name
  @movie_name
end

#ratingObject (readonly)

Returns the value of attribute rating.



7
8
9
# File 'lib/osdb/sub.rb', line 7

def rating
  @rating
end

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



7
8
9
# File 'lib/osdb/sub.rb', line 7

def raw_data
  @raw_data
end

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/osdb/sub.rb', line 7

def url
  @url
end

#user_ranksObject (readonly)

Returns the value of attribute user_ranks.



7
8
9
# File 'lib/osdb/sub.rb', line 7

def user_ranks
  @user_ranks
end

Instance Method Details

#<=>(other) ⇒ Object



23
24
25
# File 'lib/osdb/sub.rb', line 23

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

#scoreObject

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



30
31
32
# File 'lib/osdb/sub.rb', line 30

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

#uploader_scoreObject



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

def uploader_score
  user_ranks.empty? ? 1 : 2
end