Class: DOC

Inherits:
Thor
  • Object
show all
Defined in:
lib/run.rb

Overview

Thor class

Instance Method Summary collapse

Instance Method Details

#__print_createdateObject



279
280
281
282
# File 'lib/run.rb', line 279

def __print_createdate
   = YAML.load(`gem specification pdfmd metadata`)
  puts ['revision']
end

#__print_versionObject



273
274
275
# File 'lib/run.rb', line 273

def __print_version
  puts VERSION
end

#clean(*filename) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/run.rb', line 78

def clean(*filename)

  filename.each do |current_file|

    # Skip non-pdf documents
    ! File.extname(current_file).match(/\.pdf/) ? next : ''

    pdfdoc      = Pdfmdclean.new current_file
    pdfdoc.tags = options[:tags]
    pdfdoc.run

    # Unset
    pdfdoc      = ''

  end
end

#config(subcommand = '') ⇒ Object



101
102
103
104
105
106
# File 'lib/run.rb', line 101

def config(subcommand = '')

  pdfdoc = Pdfmdconfig.new ''
  puts pdfdoc.show_config subcommand

end

#edit(*filename) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/run.rb', line 116

def edit(*filename)

  filename.each do |current_file|

    # Skip non-pdf documents
    ! File.extname(current_file).match(/\.pdf/) ? next : ''

    pdfdoc            = Pdfmdedit.new current_file
    tags              = pdfdoc.determineValidSetting(options[:tag],'edit:tags')
    pdfdoc.opendoc    = pdfdoc.determineValidSetting(options[:opendoc], 'edit:opendoc')
    pdfdoc.pdfviewer  = pdfdoc.determineValidSetting(nil, 'edit:pdfviewer')
    pdfdoc.set_tags tags
    pdfdoc.update_tags
    pdfdoc.write_tags current_file

    # If the file shall be renamed at the same time, trigger the other task
    if pdfdoc.determineValidSetting(options[:rename], 'edit:rename')

      #rename filename
      pdfdoc.log('info', 'Running rename command.')
      rename current_file

    end

    # Unset the object
    pdfdoc = ''

  end

end

#rename(*filename) ⇒ Object



244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/run.rb', line 244

def rename(*filename)

  filename.each do |current_file|

    # Skip non-pdf documents
    ! File.extname(current_file).match(/\.pdf/) ? next : ''

    pdfdoc                = Pdfmdrename.new current_file
    pdfdoc.dryrun         = pdfdoc.determineValidSetting(options[:dryrun],'rename:dryrun')
    pdfdoc.allkeywords    = pdfdoc.determineValidSetting(options[:allkeywords],'rename:allkeywords')
    pdfdoc.outputdir      = pdfdoc.determineValidSetting(options[:outputdir], 'rename:outputdir')
    if nrkeywords = pdfdoc.determineValidSetting(options[:nrkeywords], 'rename:nrkeywords' )
      pdfdoc.nrkeywords = nrkeywords
    end
    pdfdoc.copy           = pdfdoc.determineValidSetting(options[:copy], 'rename:copy')
    pdfdoc.rename

    # Unset
    pdfdoc                = ''

  end

end

#show(*filename) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/run.rb', line 52

def show(*filename)

  filename.each do |current_file|

    # Skip non-pdf documents
    ! File.extname(current_file).match(/\.pdf/) ? next : ''

    pdfdoc            = Pdfmdshow.new current_file
    format            = pdfdoc.determineValidSetting(options[:format], 'show:format')
    show_filename     = pdfdoc.determineValidSetting(options[:includepdf], 'show:includepdf')
    show_tags         = pdfdoc.determineValidSetting(options[:tag], 'show:tags')
    pdfdoc.set_outputformat format
    pdfdoc.show_filename show_filename
    pdfdoc.set_tags show_tags
    puts pdfdoc.show_metatags

    pdfdoc            = ''

  end
end

#sort(input) ⇒ Object



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/run.rb', line 205

def sort(input)

  if File.file?(input)
    pdfdoc              = Pdfmdsort.new input
    pdfdoc.copy         = pdfdoc.determineValidSetting(options[:copy], 'sort:copy')
    pdfdoc.interactive  = pdfdoc.determineValidSetting(options[:interactive], 'sort:interactive')
    pdfdoc.destination  = pdfdoc.determineValidSetting(options[:destination], 'sort:destination')
    pdfdoc.overwrite    = pdfdoc.determineValidSetting(options[:overwrite], 'sort:overwrite')
    pdfdoc.dryrun       = pdfdoc.determineValidSetting(options[:dryrun], 'sort:dryrun')
    pdfdoc.sort
  else

    # Run the actions for all files
    Dir.glob(input.chomp + '/*.pdf').each do |filename|
      pdfdoc              = Pdfmdsort.new filename
      pdfdoc.copy         = pdfdoc.determineValidSetting(options[:copy], 'sort:copy')
      pdfdoc.interactive  = pdfdoc.determineValidSetting(options[:interactive], 'sort:interactive')
      pdfdoc.destination  = pdfdoc.determineValidSetting(options[:destination], 'sort:destination')
      pdfdoc.overwrite    = pdfdoc.determineValidSetting(options[:overwrite], 'sort:overwrite')
      pdfdoc.dryrun       = pdfdoc.determineValidSetting(options[:dryrun], 'sort:dryrun')
      pdfdoc.sort
    end

  end

end

#stat(input) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/run.rb', line 154

def stat(input)

    = Hash.new
  currentOutput = Hash.new

  if File.file?(input)
    puts 'Input is a single file.'
    puts 'n.a.y.'
  else

    # Iterate through all Files an collect the metadata
    recursive = options[:recursive] ? '/**' : ''

    # Count the number of files quickly to show an overview
    # nooFiles = numberOfFiles
    nooFiles = Dir[File.join(input.chomp, recursive, '*.pdf')].count { |file| File.file?(file) }
    currentNooFiles = 0
    Dir.glob("#{input.chomp}#{recursive}/*.pdf").each do |filename|

      # Print percentage
      currentNooFiles = currentNooFiles + 1
      percentage = 100 / nooFiles * currentNooFiles
      print "\r Status: #{percentage} % of #{nooFiles} files processed.   "

      pdfdoc = Pdfmd.new filename
       = {}
      currentOutput[File.basename(filename)] = pdfdoc..to_s
      pdfdoc = nil

    end
    puts ''
    puts ''

    pdfstat = Pdfmdstat.new(currentOutput)
    pdfstat.tags options[:tags]
    pdfstat.

  end

end