Skip to content

Commit f457e0f

Browse files
Refactor ShowList private methods
1 parent 2f4df63 commit f457e0f

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

lib/addic7ed/show_list.rb

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,33 @@ def url_segment_for
1919

2020
private
2121

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+
2242
def humanized_name
2343
@humanized_name ||= raw_name.
2444
gsub(/[_\.]+/, ' ').
2545
gsub(/ (US|UK)( |$)/i, ' (\1)\2').
2646
gsub(/ (\d{4})( |$)/i, ' (\1)\2')
2747
end
2848

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-
4149
def addic7ed_shows
4250
@@addic7ed_shows ||= Nokogiri::HTML(addic7ed_homepage.body).css("select#qsShow option:not(:first-child)").map(&:text)
4351
end

0 commit comments

Comments
 (0)