Class: Panchira::Resolver
- Inherits:
-
Object
- Object
- Panchira::Resolver
- Defined in:
- lib/panchira/resolvers/resolver.rb
Overview
Resolver is a class that actually get attributes by fetching designated url. This class is the default resolver for pages.
To create your own resolver, first you make a class that extends Resolver, and then register it by ::Panchira::Extensions::register(). Then ::Panchira::fetch will pick up your resolver when Resolver::applicable?() is true.
Direct Known Subclasses
DlsiteResolver, Fanza::FanzaResolver, ImageResolver, IwaraResolver, KomifloResolver, MelonbooksResolver, Narou::NcodeResolver, Narou::Novel18Resolver, NijieResolver, PixivNovelResolver, PixivResolver, TwitterResolver
Constant Summary collapse
- URL_REGEXP =
URL pattern that a resolver tries to resolve. You must override this in subclasses to limit which urls to resolve.
URI::DEFAULT_PARSER.make_regexp
Class Method Summary collapse
-
.applicable?(url) ⇒ Boolean
Tell whether the url is applicable for this resolver.
Instance Method Summary collapse
-
#fetch ⇒ Object
This function is called right after this Resolver instance is made.
-
#initialize(url, options = nil) ⇒ Resolver
constructor
A new instance of Resolver.
Constructor Details
#initialize(url, options = nil) ⇒ Resolver
Returns a new instance of Resolver.
14 15 16 17 |
# File 'lib/panchira/resolvers/resolver.rb', line 14 def initialize(url, = nil) @url = url @options = end |
Class Method Details
.applicable?(url) ⇒ Boolean
Tell whether the url is applicable for this resolver. ::Panchira::fetch uses this method to choose a Resolver for a URL.
49 50 51 |
# File 'lib/panchira/resolvers/resolver.rb', line 49 def applicable?(url) url =~ self::URL_REGEXP end |
Instance Method Details
#fetch ⇒ Object
This function is called right after this Resolver instance is made. Fetch page from @url and return PanchiraResult.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/panchira/resolvers/resolver.rb', line 21 def fetch result = PanchiraResult.new @page = fetch_page(@url) result.canonical_url = parse_canonical_url @page = fetch_page(result.canonical_url) if @url != result.canonical_url after_fetch if respond_to?(:after_fetch, true) result.title = parse_title result.description = parse_description result.image = parse_image result. = if respond_to?(:parse_authors, true) result. = else result. = end result.circle = parse_circle result.resolver = parse_resolver result end |