sources: factor out Source::URL::ArtStation.

This commit is contained in:
evazion
2022-02-26 21:01:16 -06:00
parent 9169f00e80
commit fcf517834d
4 changed files with 123 additions and 66 deletions

View File

@@ -10,7 +10,7 @@ module Danbooru
# @return [Addressable:URI] The parsed and normalized URL.
attr_reader :url
delegate :domain, :host, :site, :path, to: :url
delegate :domain, :host, :site, :path, :query, to: :url
# Parse a string into a URL, or raise an exception if the string is not a valid HTTPS or HTTPS URL.
#
@@ -62,5 +62,18 @@ module Danbooru
def params
url.query_values.to_h.with_indifferent_access
end
# Return the subdomain of the URL, or nil if absent. For example, for "http://senpenbankashiki.hp.infoseek.co.jp", the
# subdomain is "senpenbankashiki.hp", the domain is "infoseek.co.jp", the SLD is "infoseek", and the TLD is "co.jp".
#
# @return [String, nil]
def subdomain
parsed_domain.trd
end
# @return [PublicSuffix::Domain]
def parsed_domain
@parsed_domain ||= PublicSuffix.parse(host)
end
end
end