@@ -19,25 +19,33 @@ def url_segment_for
19
19
20
20
private
21
21
22
+ def shows_matching_exactly
23
+ @shows_matching_exactly ||= addic7ed_shows . select { |addic7ed_show | is_matching? addic7ed_show }
24
+ end
25
+
26
+ def shows_matching_without_year
27
+ @shows_matching_without_year ||= addic7ed_shows . select { |addic7ed_show | is_matching? addic7ed_show , :comparer_without_year }
28
+ end
29
+
30
+ def default_comparer ( showname )
31
+ showname . downcase . gsub ( "'" , "" )
32
+ end
33
+
34
+ def comparer_without_year ( showname )
35
+ default_comparer ( showname ) . gsub ( / \( \d {4}\) ( |$)/ , '\1' )
36
+ end
37
+
38
+ def is_matching? ( addic7ed_show , comparer = :default_comparer )
39
+ [ humanized_name , addic7ed_show ] . map ( &method ( comparer ) ) . reduce ( :== )
40
+ end
41
+
22
42
def humanized_name
23
43
@humanized_name ||= raw_name .
24
44
gsub ( /[_\. ]+/ , ' ' ) .
25
45
gsub ( / (US|UK)( |$)/i , ' (\1)\2' ) .
26
46
gsub ( / (\d {4})( |$)/i , ' (\1)\2' )
27
47
end
28
48
29
- def shows_matching_exactly
30
- @shows_matching_exactly ||= addic7ed_shows . select do |addic7ed_show |
31
- [ addic7ed_show , humanized_name ] . map { |showname | showname . downcase . gsub ( "'" , "" ) } . reduce ( :== )
32
- end
33
- end
34
-
35
- def shows_matching_without_year
36
- @shows_matching_without_year ||= addic7ed_shows . select do |addic7ed_show |
37
- [ addic7ed_show , humanized_name ] . map { |showname | showname . downcase . gsub ( "'" , "" ) . gsub ( / \( \d {4}\) ( |$)/ , '\1' ) } . reduce ( :== )
38
- end
39
- end
40
-
41
49
def addic7ed_shows
42
50
@@addic7ed_shows ||= Nokogiri ::HTML ( addic7ed_homepage . body ) . css ( "select#qsShow option:not(:first-child)" ) . map ( &:text )
43
51
end
0 commit comments