5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/subtitle_source/array.rb', line 5
def based_on(string, args = {})
result = self.any? ? self.map do |s|
[Levenshtein.distance(s.release_name, string, args[:limit] || 0.4), s]
end.reject do |value|
value.first.nil?
end.sort_by do |value|
value.first
end.map(&:last).first : nil
return if result.nil?
if result.release_name =~ /(s\d{2}e\d{2})/i
return unless string.match(/#{$1}/i)
end
if result.release_name =~ /((19|20)\d{2})/
return unless string.match(/#{$1}/)
end
return result
end
|