Class: PdfParadise::SetPdfTitle

Inherits:
Base
  • Object
show all
Defined in:
lib/pdf_paradise/set_pdf_title.rb

Overview

PdfParadise::SetPdfTitle

Constant Summary collapse

SHALL_WE_DELETE_THE_ORIGINAL_FILE =
#

SHALL_WE_DELETE_THE_ORIGINAL_FILE

#
true

Constants inherited from Base

Base::NAMESPACE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#basename, #be_verbose?, #change_directory, #commandline_arguments?, #copy_file, #delete_file, #e, #ecomment, #esystem, #first_argument?, #gold, #infer_the_namespace, #input_without_leading_hyphens?, #internal_hash?, #is_an_image_file?, #is_on_roebe?, #lightsteelblue, #log_dir?, #mkdir, #mv, #n_pages?, #namespace?, #no_file_at, #opne, #opnn, #orange, #reset_the_internal_hash, #return_commandline_arguments_starting_with_hyphens, #return_files_from_the_commandline_arguments, #return_pwd, #rev, #set_be_quiet, #set_commandline_arguments, #steelblue, #try_to_ensure_that_this_directory_exists, #write_what_into

Constructor Details

#initialize(name_of_the_pdf_file = nil, new_title_to_use = 'Default title', run_already = true) ⇒ SetPdfTitle

#

initialize

#


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/pdf_paradise/set_pdf_title.rb', line 41

def initialize(
    name_of_the_pdf_file = nil,
    new_title_to_use     = 'Default title',
    run_already          = true
  )
  reset
  if name_of_the_pdf_file.is_a?(Array) and (name_of_the_pdf_file.size > 1)
    new_title_to_use     = name_of_the_pdf_file.last
    if new_title_to_use.include? '--'
      # =================================================================== #
      # Assume this to be a commandline instruction then.
      # =================================================================== #
      case new_title_to_use # case tag
      # =================================================================== #
      # === --set-title=03 Stickstoff und Aminosäuren
      # =================================================================== #
      when /-?-?set(-|_)?title=(.+)$/
        new_title_to_use = $2.to_s.dup
      end
    end
    name_of_the_pdf_file = name_of_the_pdf_file.first
  end
  set_pdf_file(
    name_of_the_pdf_file
  )
  set_title(new_title_to_use)
  run if run_already
end

Class Method Details

.[](i = ARGV) ⇒ Object

#

PdfParadise::SetPdfTitle[]

#


192
193
194
# File 'lib/pdf_paradise/set_pdf_title.rb', line 192

def self.[](i = ARGV)
  new(i)
end

Instance Method Details

#add_pdf_file_to_the_commandlineObject

#

add_pdf_file_to_the_commandline

#


148
149
150
# File 'lib/pdf_paradise/set_pdf_title.rb', line 148

def add_pdf_file_to_the_commandline
  @commandline_to_use << " #{@pdf_file}"
end

#add_title_to_the_commandlineObject

#

add_title_to_the_commandline

#


162
163
164
# File 'lib/pdf_paradise/set_pdf_title.rb', line 162

def add_title_to_the_commandline
  @commandline_to_use << " #{@title}"
end

#build_up_commandline_commandObject

#

build_up_commandline_command

Build up the main commandline to use here.

#


137
138
139
140
141
142
143
# File 'lib/pdf_paradise/set_pdf_title.rb', line 137

def build_up_commandline_command
  if SHALL_WE_DELETE_THE_ORIGINAL_FILE
    @commandline_to_use << ' -overwrite_original'
  end
  add_title_to_the_commandline
  add_pdf_file_to_the_commandline
end

#input?Boolean

#

input?

#

Returns:

  • (Boolean)


128
129
130
# File 'lib/pdf_paradise/set_pdf_title.rb', line 128

def input?
  @input
end

#pdf_file?Boolean Also known as: this_file?

#

pdf_file?

#

Returns:

  • (Boolean)


155
156
157
# File 'lib/pdf_paradise/set_pdf_title.rb', line 155

def pdf_file?
  @pdf_file
end

#resetObject

#

reset (reset tag)

#


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/pdf_paradise/set_pdf_title.rb', line 73

def reset
  set_title # Set a default, being nil in this case.
  # ======================================================================= #
  # === @commandline_to_use
  # ======================================================================= #
  @commandline_to_use = 'exiftool'.dup # This will be our commandline.
  # ======================================================================= #
  # === Designate the charset that is to be used next
  #
  # Next, append the charset to be used. This is usually UTF-8.
  # exiftool claims that iso-8859-1 is an invalid encoding, but latin
  # is valid, according to exiftool..
  # ======================================================================= #
  @commandline_to_use << ' -charset UTF8'
  # @commandline_to_use << ' -charset latin' # <- It works with latin.
end

#runObject

#

run (run tag)

#


184
185
186
187
# File 'lib/pdf_paradise/set_pdf_title.rb', line 184

def run
  build_up_commandline_command
  run_commandline_command
end

#run_commandline_commandObject

#

run_commandline_command

#


169
170
171
172
173
174
175
176
177
178
179
# File 'lib/pdf_paradise/set_pdf_title.rb', line 169

def run_commandline_command
  # The following clause can lead to an infinite loop, so it was disabled
  # as of May 2022. It may have to be re-evaluated at a later point.
  # if is_on_roebe? and return_pwd.include?('/home/x/books')
  #   unless PdfParadise.respond_to? :automatic_pdf_title
  #     require 'pdf_paradise/toplevel_methods/automatic_pdf_title.rb'
  #   end
  #   PdfParadise.autotitle(this_file?)
  # end
  esystem(@commandline_to_use)
end

#set_input(i = '') ⇒ Object

#

set_input

#


119
120
121
122
123
# File 'lib/pdf_paradise/set_pdf_title.rb', line 119

def set_input(i = '')
  i = i.first if i.is_a? Array
  i = i.to_s.dup
  @input = i
end

#set_pdf_file(i) ⇒ Object

#

set_pdf_file

#


109
110
111
112
113
114
# File 'lib/pdf_paradise/set_pdf_title.rb', line 109

def set_pdf_file(i)
  i = i.first if i.is_a? Array
  i = i.to_s # We need a String past this point.
  i = i.dup if i.frozen?
  @pdf_file = i
end

#set_title(i = :default) ⇒ Object

#

set_title (title tag)

Assign the title that we will use for the given .pdf file at hand.

#


95
96
97
98
99
100
101
102
103
104
# File 'lib/pdf_paradise/set_pdf_title.rb', line 95

def set_title(i = :default)
  if i == :default
    i = nil
  else
    i = i.to_s
    i = i.dup if i.frozen?
  end
  i = "-Title=\"#{i}\"" if i
  @title = i
end