Class: Metanorma::Plugin::Lutaml::SourceExtractor

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/metanorma/plugin/lutaml/source_extractor.rb

Constant Summary collapse

ANCHOR_REGEX_1 =

example:

- [[abc]]
/^\[\[(?<id>[^\]]*)\]\]\s*$/.freeze
ANCHOR_REGEX_2 =

examples:

- [#abc]
- [source#abc,ruby]
/^\[[^#,]*#(?<id>[^,\]]*)[,\]]/.freeze
ANCHOR_REGEX_3 =

examples:

- [id=abc]
- [source,id="abc"]
/^\[(?:.+,)?id=['"]?(?<id>[^,\]'"]*)['"]?[,\]]/.freeze

Constants included from Utils

Utils::LUTAML_EXP_IDX_TAG

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

create_liquid_environment, load_express_from_folder, load_express_from_index, load_express_repo_from_cache, load_express_repo_from_path, load_express_repositories, notify_render_errors, parse_document_express_indexes, processed_lines, relative_file_path, render_liquid_string, save_express_repo_to_cache

Constructor Details

#initialize(document, input_lines) ⇒ SourceExtractor

Returns a new instance of SourceExtractor.



25
26
27
28
29
30
# File 'lib/metanorma/plugin/lutaml/source_extractor.rb', line 25

def initialize(document, input_lines)
  @document = document
  @input_lines = input_lines

  @document.attributes["source_blocks"] ||= {}
end

Class Method Details

.extract(document, input_lines) ⇒ Object



32
33
34
# File 'lib/metanorma/plugin/lutaml/source_extractor.rb', line 32

def self.extract(document, input_lines)
  new(document, input_lines).extract
end

Instance Method Details

#extractObject

rubocop:disable Metrics/AbcSize



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/metanorma/plugin/lutaml/source_extractor.rb', line 36

def extract # rubocop:disable Metrics/AbcSize
  lines = @input_lines.to_enum

  loop do
    line = lines.next

    if /^embed::|^include::/.match?(line.strip)
      file_lines = read(filename(@document, line)) or next
      SourceExtractor.extract(@document, file_lines)
    elsif m = match_anchor(line)
      @document.attributes["source_blocks"][m[:id]] = read_section lines
    end
  end
end