module Mangdown
Find, download and package manga from the web
Top level library error
Find, download and package manga from the web
Constants
- VERSION
Public Class Methods
adapters()
click to toggle source
# File lib/mangdown.rb, line 37 def self.adapters @adapters ||= {} end
chapter(uri_or_instance)
click to toggle source
# File lib/mangdown.rb, line 47 def self.chapter(uri_or_instance) with_adapter(uri_or_instance, :chapter) do |instance| Mangdown::Chapter.new(instance) end end
configure_logger(options = {})
click to toggle source
# File lib/mangdown/support/logging.rb, line 21 def configure_logger(options = {}) logger_args = options.fetch(:logger_args) { [options[:file]] } @logger = Logger.new(*logger_args) @logger.level = options.fetch(:level, Logger::DEBUG) @logger end
logger()
click to toggle source
# File lib/mangdown/support/logging.rb, line 17 def logger @logger ||= configure_logger(file: STDOUT) end
manga(uri_or_instance)
click to toggle source
# File lib/mangdown.rb, line 41 def self.manga(uri_or_instance) with_adapter(uri_or_instance, :manga) do |instance| Mangdown::Manga.new(instance) end end
page(uri_or_instance)
click to toggle source
# File lib/mangdown.rb, line 53 def self.page(uri_or_instance) with_adapter(uri_or_instance, :page) do |instance| Mangdown::Page.new(instance) end end
register_adapter(name, adapter)
click to toggle source
# File lib/mangdown.rb, line 33 def self.register_adapter(name, adapter) adapters[name] = adapter end
Private Class Methods
adapter(uri)
click to toggle source
rubocop:enable Metrics/AbcSize rubocop:enable Metrics/MethodLength
# File lib/mangdown.rb, line 81 def self.adapter(uri) adapter = adapters.values.find { |a| a.for?(uri) } raise Adapter::NoAdapterError, uri unless adapter adapter end
debug_error(error, adapter, instance)
click to toggle source
# File lib/mangdown.rb, line 90 def self.debug_error(error, adapter, instance) { msg: 'Adapter method failed', adapter: adapter.class, instance: instance, error: error, error_msg: error.message, backtrace: error.backtrace }.to_s end
with_adapter(instance, instance_constructor) { |instance| ... }
click to toggle source
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
# File lib/mangdown.rb, line 61 def self.with_adapter(instance, instance_constructor) if instance.is_a?(String) adapter = adapter(instance) instance = adapter.public_send(instance_constructor, instance) else adapter = adapter(instance.url) klass = adapter.class.const_get(instance_constructor.to_s.capitalize) instance = klass.new(instance.attributes) end yield(instance) rescue Adapter::NoAdapterError raise rescue StandardError => error logger.error(debug_error(error, adapter, instance)) raise Mangdown::Error, "Adapter failed: #{error.message}" end