class Paru::Info

Information about pandoc

@!attribute version

@return [Array<Integer>] Pandoc's version, like [2, 18, 1]

@!attribute data_dir

@return [String] Pandoc's default data directory

@!attribute scripting_engine

@return [String] Pandoc's internal scripting engine, like "Lua 5.4"

Attributes

data_dir[R]
scripting_engine[R]
version[R]

Public Class Methods

new(path = "pandoc") click to toggle source

Create a new Info object

@param path [String] the path to pandoc. Defaults to ‘pandoc’, i.e., assumes it’s on the environment’s path.

# File lib/paru/info.rb, line 41
def initialize(path = "pandoc")
  begin
    # Get pandoc's version information
    version_string = ''
    IO.popen("#{path} --version", 'r+') do |p|
      p.close_write
      version_string << p.read
    end

    # Extract the version as an array of integers, like SemVer.
    @version = version_string
      .match(/pandoc.* (\d+\.\d+.*)$/)[1]
      .split(".")
      .map {|s| s.to_i}

    # Extract the data directory
    @data_dir = version_string.match(/User data directory: (.+)$/)[1]

    # Extract scripting engine
    @scripting_engine = version_string.match(/Scripting engine: (.+)$/)[1]
  rescue StandardError => err
    warn "Error extracting pandoc's information: #{err.message}"
    warn "Using made up values instead."

    @version = @version || [2, 18]
    @data_dir = @data_dir || "."
    @scripting_engine = @scripting_engine || "Lua 5.4"
  end
end

Public Instance Methods

[](key) click to toggle source

Get pandoc’s info by key like a Hash for backwards compatability.

@deprecated Use Info’s getters instead.

@param key [String|Symbol] the key for the information to look up. Info only supports keys ‘version’ and ‘data_dir’. @return [Any] Information associated with the key. @raise [Error] for an unknown key.

# File lib/paru/info.rb, line 79
def [](key)
  case key
  when "verion", :version
    version
  when "data_dir", :data_dir
    data_dir
  when "scripting_engine", :scripting_engine
    scripting_engine
  else
    throw Error.new "Info does not know key '#{key}'"
  end
end