Class: Metanorma::Release::RxlExtractor
- Inherits:
-
Object
- Object
- Metanorma::Release::RxlExtractor
- Defined in:
- lib/metanorma/release/rxl_extractor.rb
Instance Method Summary collapse
- #discover(output_dir) ⇒ Object
- #extract(rxl_path) ⇒ Object
-
#initialize(fallback_flavor: nil) ⇒ RxlExtractor
constructor
A new instance of RxlExtractor.
Constructor Details
#initialize(fallback_flavor: nil) ⇒ RxlExtractor
Returns a new instance of RxlExtractor.
12 13 14 |
# File 'lib/metanorma/release/rxl_extractor.rb', line 12 def initialize(fallback_flavor: nil) @fallback_flavor = fallback_flavor end |
Instance Method Details
#discover(output_dir) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/metanorma/release/rxl_extractor.rb', line 16 def discover(output_dir) rxl_files = Dir.glob(File.join(output_dir, '**', '*.rxl')) rxl_files.filter_map do |path| extract(path) rescue StandardError => e warn "Warning: Skipping #{path}: #{e.}" nil end end |
#extract(rxl_path) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/metanorma/release/rxl_extractor.rb', line 26 def extract(rxl_path) raise ArgumentError, "RXL file not found: #{rxl_path}" unless File.exist?(rxl_path) content = File.read(rxl_path) doc = Nokogiri::XML(content, nil, 'UTF-8', Nokogiri::XML::ParseOptions::STRICT) extract_from_xml(doc, rxl_path) rescue Nokogiri::XML::SyntaxError => e warn "Warning: Failed to parse RXL #{rxl_path}: #{e.}" (rxl_path) end |