Class: Pubid::Export::FlavorExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/pubid/export/flavor_exporter.rb

Overview

Unified metadata extractor for all flavors.

Uses the self-describing type interface (identifier_types, all_typed_stages, locate_type, locate_stage) on each flavor module. No Scheme dependency (Scheme class removed).

Open/Closed: Adding a new flavor requires only adding it to Exporter::FLAVORS. Single Responsibility: Extracts metadata from flavor modules into value objects. Single Source of Truth: Each identifier class IS the type definition.

Constant Summary collapse

WRAPPER_CLASSES =

Wrapper classes to discover per flavor (overlay patterns that wrap base identifiers)

{
  iec: %i[VapIdentifier],
  bsi: %i[ValueAddedPublication],
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flavor) ⇒ FlavorExporter

Returns a new instance of FlavorExporter.



24
25
26
# File 'lib/pubid/export/flavor_exporter.rb', line 24

def initialize(flavor)
  @flavor = flavor
end

Instance Attribute Details

#flavorObject (readonly)

Returns the value of attribute flavor.



16
17
18
# File 'lib/pubid/export/flavor_exporter.rb', line 16

def flavor
  @flavor
end

Instance Method Details

#exportObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/pubid/export/flavor_exporter.rb', line 28

def export
  mod = flavor_module
  return nil unless mod

  klasses = resolve_identifier_classes(mod)
  return nil if klasses.empty?

  fixture_data = fixture_examples
  seen_keys = Set.new

  identifier_types = klasses.filter_map do |klass|
    info = extract_type_info(klass)
    next if seen_keys.include?(info[:key])

    seen_keys << info[:key]

    stages = extract_typed_stages(klass)
    examples = match_examples(fixture_data, info[:key]&.to_s, klass)

    IdentifierTypeResult.new(
      key: info[:key],
      title: info[:title],
      short: info[:short],
      abbr: info[:abbr],
      typed_stages: stages,
      examples: examples,
    )
  end

  FlavorResult.new(
    flavor: flavor,
    identifier_types: identifier_types,
    wrapper_types: extract_wrapper_types,
    attributes: extract_attributes(klasses.first),
  )
end