Class: Abqari::Importers::Base

Inherits:
Object
  • Object
show all
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.

Direct Known Subclasses

Ghost, Jekyll, Substack

Defined Under Namespace

Classes: ImportedPost, Options

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#reportObject (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_nameObject

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_selectorsObject

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_postObject

Subclass-provided. Must yield ImportedPost records.

Raises:

  • (NotImplementedError)


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