moebooru: delegate to substrategy based on post source (#3911).

If the yande.re or konachan.com post has a source from a supported site,
for example Pixiv or Twitter, then delegate the artist and commentary
lookup to that substrategy.

Only do this for sources from recognized sites, not the null strategy.
This commit is contained in:
evazion
2018-10-06 14:27:34 -05:00
parent e5a4193dd4
commit c8d538f618
4 changed files with 17 additions and 23 deletions

View File

@@ -12,15 +12,12 @@ module Sources
Strategies::Nijie,
Strategies::Pawoo,
Strategies::Moebooru,
Strategies::Null # MUST BE LAST!
]
end
def self.find(url, referer=nil)
all
.detect { |strategy| strategy.match?(url, referer) }
.new(url, referer)
def self.find(url, referer=nil, default: Strategies::Null)
strategy = all.detect { |strategy| strategy.match?(url, referer) } || default
strategy&.new(url, referer)
end
def self.canonical(url, referer)