module PdflibMini::InfoReader::ClassMethods

Public Instance Methods

info_reader(method_name, keyword, default_type) click to toggle source
# File lib/pdflib_mini/info_reader.rb, line 8
def info_reader(method_name, keyword, default_type)
  define_method(keyword) do |*args|
    optlist = args.first.is_a?(String) ? args.first : ''
    options = args.last.is_a?(Hash) ? args.last : {}
    result = public_send(method_name, keyword, optlist)
    type = options.fetch(:as, default_type)
    case type
    when :raw
      info_result_as_raw(result)
    when :boolean
      info_result_as_boolean(result)
    when :string
      info_result_as_string(result)
    else # handle
      info_result_as_handle(result, type)
    end
  end

  if default_type == :boolean
    alias_method :"#{keyword}?", keyword
  end
end