class Addic7ed::ShowList
Attributes
raw_name[R]
Public Class Methods
new(raw_name)
click to toggle source
# File lib/addic7ed/show_list.rb, line 5 def initialize(raw_name) @raw_name = raw_name end
url_segment_for(raw_name)
click to toggle source
# File lib/addic7ed/show_list.rb, line 9 def self.url_segment_for(raw_name) new(raw_name).url_segment_for end
Public Instance Methods
url_segment_for()
click to toggle source
# File lib/addic7ed/show_list.rb, line 13 def url_segment_for shows_matching = shows_matching_exactly shows_matching = shows_matching_without_year if shows_matching.empty? raise ShowNotFound if shows_matching.empty? shows_matching.last.gsub(' ', '_') end
Private Instance Methods
addic7ed_homepage()
click to toggle source
# File lib/addic7ed/show_list.rb, line 53 def addic7ed_homepage Net::HTTP.start("www.addic7ed.com") do |http| request = Net::HTTP::Get.new("/") request["User-Agent"] = USER_AGENTS.sample http.request(request) end end
addic7ed_shows()
click to toggle source
# File lib/addic7ed/show_list.rb, line 49 def addic7ed_shows @@addic7ed_shows ||= Oga.parse_html(addic7ed_homepage.body).css("select#qsShow option:not(:first-child)").map(&:text) end
comparer_without_year(showname)
click to toggle source
# File lib/addic7ed/show_list.rb, line 34 def comparer_without_year(showname) default_comparer(showname).gsub(/ \(\d{4}\)( |$)/, '\1') end
default_comparer(showname)
click to toggle source
# File lib/addic7ed/show_list.rb, line 30 def default_comparer(showname) showname.downcase.gsub("'", "").gsub(".", " ").strip end
humanized_name()
click to toggle source
# File lib/addic7ed/show_list.rb, line 42 def humanized_name @humanized_name ||= raw_name. gsub(/[_\.]+/, ' '). gsub(/ (US|UK)( |$)/i, ' (\1)\2'). gsub(/ (\d{4})( |$)/i, ' (\1)\2') end
is_matching?(addic7ed_show, comparer = :default_comparer)
click to toggle source
# File lib/addic7ed/show_list.rb, line 38 def is_matching?(addic7ed_show, comparer = :default_comparer) [humanized_name, addic7ed_show].map(&method(comparer)).reduce(:==) end
shows_matching_exactly()
click to toggle source
# File lib/addic7ed/show_list.rb, line 22 def shows_matching_exactly @shows_matching_exactly ||= addic7ed_shows.select{ |addic7ed_show| is_matching? addic7ed_show } end
shows_matching_without_year()
click to toggle source
# File lib/addic7ed/show_list.rb, line 26 def shows_matching_without_year @shows_matching_without_year ||= addic7ed_shows.select{ |addic7ed_show| is_matching? addic7ed_show, :comparer_without_year } end