Module: Menuconform::Importers

Defined in:
lib/menuconform/importers.rb,
lib/menuconform/importers/base.rb,
lib/menuconform/importers/ncr_menu.rb

Overview

Registry of source-format importers. Each importer registers itself under a CLI-facing format name (e.g. "ncr-menu"); default mapping config lives in config/importers/.json and can be overridden per run.

Defined Under Namespace

Classes: Base, NcrMenu, Result, SourceError

Constant Summary collapse

CONFIG_DIR =
File.join(File.expand_path("../..", __dir__), "config", "importers")

Class Method Summary collapse

Class Method Details

.build(format) ⇒ Object

Raises:



21
22
23
24
25
# File 'lib/menuconform/importers.rb', line 21

def build(format)
  klass = @registry[format]
  raise SourceError, "unknown import format #{format.inspect} (known: #{names.join(', ')})" unless klass
  klass.new
end

.default_config(format) ⇒ Object



27
28
29
30
# File 'lib/menuconform/importers.rb', line 27

def default_config(format)
  path = File.join(CONFIG_DIR, "#{format.tr('-', '_')}.json")
  File.exist?(path) ? JSON.parse(File.read(path, encoding: "UTF-8")) : {}
end

.import(format, source, config: nil) ⇒ Object

One-call convenience: source hash -> Result with IR doc.



33
34
35
# File 'lib/menuconform/importers.rb', line 33

def import(format, source, config: nil)
  Importers.build(format).call(source, config: config || default_config(format))
end

.namesObject



19
# File 'lib/menuconform/importers.rb', line 19

def names = @registry.keys.sort

.register(klass) ⇒ Object



15
16
17
# File 'lib/menuconform/importers.rb', line 15

def register(klass)
  @registry[klass.format_name] = klass
end