Class: Metanorma::Mirror::Output::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/metanorma/mirror/output/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_path:, output_path:, format: :inline, **options) ⇒ Builder

Returns a new instance of Builder.



11
12
13
14
15
16
# File 'lib/metanorma/mirror/output/builder.rb', line 11

def initialize(xml_path:, output_path:, format: :inline, **options)
  @xml_path = xml_path
  @output_path = output_path
  @format = format
  @options = options
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



9
10
11
# File 'lib/metanorma/mirror/output/builder.rb', line 9

def format
  @format
end

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/metanorma/mirror/output/builder.rb', line 9

def options
  @options
end

#output_pathObject (readonly)

Returns the value of attribute output_path.



9
10
11
# File 'lib/metanorma/mirror/output/builder.rb', line 9

def output_path
  @output_path
end

#xml_pathObject (readonly)

Returns the value of attribute xml_path.



9
10
11
# File 'lib/metanorma/mirror/output/builder.rb', line 9

def xml_path
  @xml_path
end

Instance Method Details

#buildObject

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/metanorma/mirror/output/builder.rb', line 18

def build
  pipeline = Pipeline.new(
    xml_path: @xml_path,
    flavor: @options[:flavor],
    title: @options[:title] || File.basename(@xml_path, ".*"),
    id_strategy: @options[:id_strategy],
  )

  guide = pipeline.process

  format_class = Formats.lookup(@format)
  raise ArgumentError, "Unknown format: #{@format}" unless format_class

  formatter = format_class.new(dist_dir: @options[:dist_dir])
  formatter.write(@output_path, guide, title: @options[:title])

  @output_path
end