Class: Metanorma::Release::RxlExtractor

Inherits:
Object
  • Object
show all
Extended by:
Extractor
Defined in:
lib/metanorma/release/rxl_extractor.rb

Class Method Summary collapse

Methods included from Extractor

discover

Class Method Details

.discover(output_dir) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/metanorma/release/rxl_extractor.rb', line 8

def self.discover(output_dir)
  require "relaton/bib"
  Dir.glob(File.join(output_dir, "**", "*.rxl")).filter_map do |path|
    from_rxl(path)
  rescue StandardError => e
    Metanorma::Release.logger.warn "Skipping #{path}: #{e.message}"
    nil
  end
end

.from_rxl(rxl_path) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/metanorma/release/rxl_extractor.rb', line 18

def self.from_rxl(rxl_path)
  unless File.exist?(rxl_path)
    raise ArgumentError,
          "RXL file not found: #{rxl_path}"
  end

  content = File.read(rxl_path)
  bib = Relaton::Bib::Item.from_xml(content)
  build_from_bib(bib, rxl_path)
rescue StandardError => e
  Metanorma::Release.logger.warn "Failed to parse RXL #{rxl_path}: #{e.message}"
  fallback_from_rxl(rxl_path)
end