class Metanorma::Cli::Compiler

Attributes

extensions[R]
extract[R]
file[R]
options[R]

Public Class Methods

compile(file, options) click to toggle source

@return [Array<String>]

# File lib/metanorma/cli/compiler.rb, line 34
def self.compile(file, options)
  new(file, options).compile
end
new(file, options) click to toggle source
# File lib/metanorma/cli/compiler.rb, line 8
def initialize(file, options)
  validate_file_path(file)
  @file = file
  @options = options
  normalize_special_options
end

Public Instance Methods

compile() click to toggle source

@return [Array<String>]

# File lib/metanorma/cli/compiler.rb, line 29
def compile
  compile_file
end
validate_file_path(file) click to toggle source
# File lib/metanorma/cli/compiler.rb, line 15
def validate_file_path(file)
  path = Pathname.new(file)
  # Check if provided file path exists
  unless path.exist?
    raise ::Metanorma::Cli::Errors::FileNotFoundError.new("Specified input file '#{file}' does not exist")
  end

  # Check if provided file is really a file
  unless path.file?
    raise ::Metanorma::Cli::Errors::FileNotFoundError.new("Specified input file '#{file}' is not a file")
  end
end

Private Instance Methods

compile_file() click to toggle source

@return [Array<String>]

# File lib/metanorma/cli/compiler.rb, line 43
def compile_file
  c = Compile.new
  c.compile(file, serialize_options)
  c.errors
end
customize_options() click to toggle source
# File lib/metanorma/cli/compiler.rb, line 53
def customize_options
  extract_option.merge(extension_option)
end
extension_option() click to toggle source
# File lib/metanorma/cli/compiler.rb, line 65
def extension_option
  !extensions.empty? ? { extension_keys: extensions.map(&:to_sym) } : {}
end
extract_option() click to toggle source
# File lib/metanorma/cli/compiler.rb, line 57
def extract_option
  Hash.new.tap do |hash|
    hash[:extract] = extract[0]
    hash[:extract_type] =
      extract.size > 0 ? extract[0..-1].map(&:to_sym) : []
  end
end
normalize_special_options() click to toggle source
# File lib/metanorma/cli/compiler.rb, line 77
def normalize_special_options
  @extract = (options.delete(:extract) || "").split(",")
  @extensions = (options.delete(:extensions) || "").split(",")
  options[:require] = [options[:require]] if options[:require]
end
serialize(options) click to toggle source
# File lib/metanorma/cli/compiler.rb, line 69
def serialize(options)
  Hash.new.tap do |hash|
    options.each do |key, value|
      hash[key.to_sym] = value unless value.nil?
    end
  end
end
serialize_options() click to toggle source
# File lib/metanorma/cli/compiler.rb, line 49
def serialize_options
  serialize(options.merge(customize_options))
end