Refactor normalize_for_artist_finder!

Refactors things such that Sources::Site has a normalize_for_artist_finder!
method that delegates to the strategy for the appropriate site. This way
any site that needs to normalize URLs for the artist finder can do so.
This commit is contained in:
evazion
2014-10-05 11:59:06 -05:00
parent a36472f35b
commit 7f3b98969f
4 changed files with 15 additions and 4 deletions

View File

@@ -118,7 +118,7 @@ class ArtistsController < ApplicationController
end
def finder
url = Sources::Strategies::Pixiv.new(url).normalize_for_artist_finder!(params[:url])
url = Sources::Site.new(params[:url]).normalize_for_artist_finder!
@artists = Artist.url_matches(url).order("id desc").limit(20)
respond_with(@artists) do |format|

View File

@@ -20,6 +20,14 @@ module Sources
end
end
def normalize_for_artist_finder!
if available?
return strategy.normalize_for_artist_finder!
else
return url
end
end
def translated_tags
untranslated_tags = tags
untranslated_tags = untranslated_tags.map(&:first)

View File

@@ -18,6 +18,10 @@ module Sources
raise NotImplementedError
end
def normalize_for_artist_finder!
url
end
def site_name
raise NotImplementedError
end

View File

@@ -25,13 +25,12 @@ module Sources
@pixiv_moniker
end
def normalize_for_artist_finder!(url)
illust_id = illust_id_from_url(url)
def normalize_for_artist_finder!
# http://i2.pixiv.net/img04/img/syounen_no_uta/46170939_m.jpg
if url =~ %r!/img/([^/]+)/\d+(?:_\w+)?\.(?:jpg|jpeg|png|gif)!i
username = $1
else
illust_id = illust_id_from_url(url)
get_metadata_from_spapi!(illust_id) do |metadata|
username = metadata[24]
end