Class: Abqari::Importers::Base
- Inherits:
-
Object
- Object
- Abqari::Importers::Base
- Defined in:
- lib/abqari/importers/base.rb
Overview
Shared writer pipeline. Subclasses implement each_post (yielding
ImportedPost records); this base class handles HTML→Markdown
conversion, image download + rewriting, slug collision resolution,
frontmatter assembly, idempotency (skip if file exists), and
report accumulation.
The base intentionally knows nothing about source formats — that split keeps each importer small (just "parse this source into records") and concentrates all the engine-specific behaviour (bundle layout, frontmatter conventions, image pipeline interop) in one place.
Defined Under Namespace
Classes: ImportedPost, Options
Instance Attribute Summary collapse
-
#report ⇒ Object
readonly
Returns the value of attribute report.
Class Method Summary collapse
-
.short_name ⇒ Object
Class-level name used in the report header ("substack", "ghost", "jekyll").
-
.strip_selectors ⇒ Object
Subclasses override this to declare platform-chrome selectors that the base writer should pre-strip from every body before markdown conversion.
Instance Method Summary collapse
-
#each_post ⇒ Object
Subclass-provided.
-
#initialize(source:, opts: nil) ⇒ Base
constructor
A new instance of Base.
-
#run! ⇒ Object
The whole show.
Constructor Details
#initialize(source:, opts: nil) ⇒ Base
Returns a new instance of Base.
57 58 59 60 61 62 63 |
# File 'lib/abqari/importers/base.rb', line 57 def initialize(source:, opts: nil) @source = source @opts = opts || Options.new @logger = @opts.logger || ->(line) { puts line } @report = Support::Report.new(source: source, importer: self.class.short_name) @taken_slugs = Set.new end |
Instance Attribute Details
#report ⇒ Object (readonly)
Returns the value of attribute report.
72 73 74 |
# File 'lib/abqari/importers/base.rb', line 72 def report @report end |
Class Method Details
.short_name ⇒ Object
Class-level name used in the report header ("substack", "ghost", "jekyll"). Subclasses override if the constant doesn't follow the convention.
68 69 70 |
# File 'lib/abqari/importers/base.rb', line 68 def self.short_name name.split('::').last.downcase end |
.strip_selectors ⇒ Object
Subclasses override this to declare platform-chrome selectors that the base writer should pre-strip from every body before markdown conversion.
213 214 215 |
# File 'lib/abqari/importers/base.rb', line 213 def self.strip_selectors [] end |
Instance Method Details
#each_post ⇒ Object
Subclass-provided. Must yield ImportedPost records.
86 87 88 |
# File 'lib/abqari/importers/base.rb', line 86 def each_post raise NotImplementedError end |
#run! ⇒ Object
The whole show. Subclasses call super from their own run!
if they need pre/post hooks, but the default implementation is
enough for every importer we ship.
77 78 79 80 81 82 83 |
# File 'lib/abqari/importers/base.rb', line 77 def run! each_post do |post| process(post) end finalise @report end |