class Pdf2htmlDocker::OptionBuilder

Attributes

keys[R]

Public Class Methods

new(args, options = {}) click to toggle source
# File lib/pdf2html_docker/option_builder.rb, line 65
def initialize(args, options = {})
  @keys = (CONVERTER_OPTIONS.keys & options.keys) + CONVERTER_ARGS
  @options = normalize_options(options)
  @args = args
end

Public Instance Methods

to_h() click to toggle source
# File lib/pdf2html_docker/option_builder.rb, line 78
def to_h
  @options.merge(@args)
end
to_s() click to toggle source
# File lib/pdf2html_docker/option_builder.rb, line 71
def to_s
  return '' if @keys.empty?

  (array_from_options(@options, CONVERTER_OPTIONS) +
    CONVERTER_ARGS).join(' ')
end

Private Instance Methods

array_from_options(hash, opts = hash) click to toggle source
# File lib/pdf2html_docker/option_builder.rb, line 92
def array_from_options(hash, opts = hash)
  hash.flat_map do |key, _val|
    [opts[key].to_s, key.to_sym.inspect.to_s]
  end
end
normalize_options(options) click to toggle source
# File lib/pdf2html_docker/option_builder.rb, line 84
def normalize_options(options)
  return {} if options.nil? || @keys.nil?

  @keys.each_with_object({}) do |f, hash|
    hash[f] = options[f].to_s unless options[f].nil?
  end
end