pdfmd 2.1.6 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e2ba1b3dab8288ed43b930c7e27b1754fc436f5
4
- data.tar.gz: b2a0cfb407738c31d9b465bc2711b7c2b04ff650
3
+ metadata.gz: 58d5e2cab3403b63a10160c42611014d6cac1ee3
4
+ data.tar.gz: ee23d47ddf7e0448f1bf67fba2f4e61847af16a7
5
5
  SHA512:
6
- metadata.gz: d02be348bfe4301f09e3ca7e093c4d4585968f8229e56b759903ae2822b4a072f6030de75976f261a1c0ccccfe605988d01b71b22e49cb17bf645e20e0a60beb
7
- data.tar.gz: 31051acfda07bd823eede7653917b74404e4d55948fd9b057156a4d082bda8697c56125777924034dfc5e4a84d7797d797c66711694fa42d4c83711866551954
6
+ metadata.gz: 117cac8d9bbdb9d1e38a4275fe2acaf596f8ef165008516f996506a5acfc9cc9268185512bcf89476bca474606fd7d3f31eea0120e82f644b4456896fa5c86a3
7
+ data.tar.gz: 8b9f96ebdcf351488006551a2d5727366ba46b86635b8d9b7b160919332d623b354727ff4dc784e2ba4393ea69d3beb9a128ca078d5795eace03d2df2fb98365
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # Version 2.2.0
2
+ - Adding parameter 'typo' to command `sort`.
3
+
1
4
  # Version 2.1.6
2
5
  - Modified command `sort` to also support shell file extension.
3
6
 
data/bin/pdfmd CHANGED
@@ -7,7 +7,7 @@ require "fileutils"
7
7
  require "i18n"
8
8
  require 'pathname'
9
9
 
10
- VERSION = '2.1.6'
10
+ VERSION = '2.2.0'
11
11
  NAME = 'pdfmd'
12
12
 
13
13
  #
@@ -207,6 +207,7 @@ method_option :copy, :aliases => '-c', :required => false, :type => :boolean, :d
207
207
  method_option :interactive, :aliases => '-i', :required => false, :type => :boolean, :desc => 'Enable/Disable interactive sorting'
208
208
  method_option :overwrite, :alises => '-o', :required => false, :type => :boolean, :desc => 'Enable/Disable file overwrite.', :lazy_default => true
209
209
  method_option :dryrun, :aliases => '-n', :required => false, :type => :boolean, :desc => 'Run without changing something'
210
+ method_option :typo, :aliases => '-t', :required => false, :type => :boolean, :desc => 'Try to find typos before sorting into folders.', :lazy_default => true
210
211
  def sort(*input)
211
212
 
212
213
  input.each do |file|
@@ -218,6 +219,7 @@ def sort(*input)
218
219
  pdfdoc.destination = pdfdoc.determineValidSetting(options[:destination], 'sort:destination')
219
220
  pdfdoc.overwrite = pdfdoc.determineValidSetting(options[:overwrite], 'sort:overwrite')
220
221
  pdfdoc.dryrun = pdfdoc.determineValidSetting(options[:dryrun], 'sort:dryrun')
222
+ pdfdoc.typo = pdfdoc.determineValidSetting(options[:typo], 'sort:typo')
221
223
  pdfdoc.sort
222
224
 
223
225
  else
data/lib/pdfmd/explain.rb CHANGED
@@ -12,6 +12,7 @@ when ''
12
12
  puts '- keywords'
13
13
  puts '- subject'
14
14
  puts '- title'
15
+ puts '- typo'
15
16
  puts ' '
16
17
  puts "Run `$ #{pdfmd} explain <subject>` to get more details."
17
18
  else
@@ -0,0 +1,6 @@
1
+ [typo]
2
+ Parameter for the command 'sort'.
3
+ If parameter is set, a warning will appear during the sorting process when a target directory is already present, which is similar to the new one that shall be created.
4
+ This usually indicates a typo in the author field, which then is reflected in the naming of the sub-directory in the sorting target.
5
+ The user then can either decide to continue or abort the sorting process.
6
+
@@ -54,6 +54,12 @@ If set to 'true' the command will overwrite any existing file at the target dest
54
54
 
55
55
 
56
56
 
57
+ --typo, -t
58
+
59
+ If set to 'true' (or set at all) similar sub-directories in the sorting target directory will be reported before a new folder is being created. Similar sub-directories can be caused by typos in the author field for the document.
60
+
61
+
62
+
57
63
  === Replacement rules
58
64
 
59
65
  The subdirectories for the documents are generated from the values in the
@@ -3,16 +3,20 @@
3
3
  # TODO: Author values with a slave One/two should be sorted into one/two/yyyymmdd-one_to-xxx.pdf
4
4
  class Pdfmdsort < Pdfmd
5
5
 
6
- attr_accessor :filename, :dryrun, :copy, :interactive, :destination, :overwrite
6
+ require 'fuzzystringmatch'
7
+
8
+ attr_accessor :filename, :dryrun, :copy, :interactive, :destination, :overwrite, :typo
7
9
 
8
10
  # Initialize
9
11
  def initialize(input)
10
12
  super input
11
- @destination = '.'
12
- @interactive = false
13
- @copy = false
14
- @dryrun = false
15
- @overwrite = false
13
+ @stringSimBorder = 0.8 # Defines the value of the typo check
14
+ @destination = '.'
15
+ @interactive = false
16
+ @copy = false
17
+ @dryrun = false
18
+ @overwrite = false
19
+ @typo = false
16
20
  end
17
21
 
18
22
 
@@ -44,6 +48,30 @@ class Pdfmdsort < Pdfmd
44
48
  I18n.transliterate(author).downcase # Normalising
45
49
  end
46
50
 
51
+ # Method compares string from 'targetdir' with all subfolders in the targetdir
52
+ # in order to find similarities in writing.
53
+ def findSimilarTargetdir( targetdir )
54
+
55
+ self.log('debug', "Running method 'findSimilarTarget' with parameter '#{targetdir}'.")
56
+
57
+ fuzzy = FuzzyStringMatch::JaroWinkler.create( :native )
58
+ returnValue = false
59
+
60
+ # Get all subfolders
61
+ subDirectories = Dir[@destination + '/*']
62
+ subDirectories.each do |fullPathFolder|
63
+ stringSimilarity = fuzzy.getDistance(
64
+ fullPathFolder.gsub(@destination + '/', ''),
65
+ targetdir.gsub(@destination + '/', '')
66
+ )
67
+ if stringSimilarity > @stringSimBorder
68
+ self.log('debug', "findSimilarTargetdir: Found String value #{stringSimilarity.to_s} for target '#{fullPathFolder}'.")
69
+ returnValue = fullPathFolder
70
+ end
71
+ end
72
+ returnValue
73
+ end
74
+
47
75
 
48
76
  #
49
77
  # Sort the file away
@@ -69,13 +97,34 @@ class Pdfmdsort < Pdfmd
69
97
  targetdir = @destination.chomp + '/' + author
70
98
  targetfile = targetdir + '/' + Pathname.new(@filename).basename.to_s
71
99
 
72
- # Create the target dir if not existing.
100
+ # Create the target directory, if it does not exist yet.
73
101
  if !File.exists? targetdir
102
+
103
+ # Check for similiar directory names which might indicate a typo in the
104
+ # current directory name.
105
+ if @typo and foundDir = self.findSimilarTargetdir(targetdir)
106
+
107
+ self.log('info', "Similar target found ('" + foundDir + "'). Request user input.")
108
+ puts 'Similar target directory detected:'
109
+ puts 'Found : ' + foundDir
110
+ puts 'Target: ' + targetdir
111
+ while answer = readUserInput('Abort? ([y]/n): ')
112
+ if answer.match(/(y|yes|j|ja|^$)/i)
113
+ self.log('info','User chose to abort sorting.')
114
+ puts 'Abort.'
115
+ exit 0
116
+ elsif answer.match(/(n|no)/i)
117
+ self.log('info', 'User chose to continue sorting.')
118
+ break
119
+ end
120
+ end
121
+ end
122
+
74
123
  if @dryrun
75
124
  self.log('info', "Dryrun: Created Directory '#{targetdir}'.")
76
125
  else
77
126
  self.log('info', "Created directory '#{targetdir}'.")
78
- puts targetdir
127
+ puts 'Created: ' + targetdir
79
128
  FileUtils.mkdir_p(targetdir)
80
129
  end
81
130
  end
data/pdfmd.gemspec CHANGED
@@ -22,4 +22,5 @@ Gem::Specification.new do |s|
22
22
  s.add_dependency 'highline', '~>1.7', '>= 1.7.1'
23
23
  s.add_dependency 'fileutils', '~>0.7','>= 0.7'
24
24
  s.add_dependency 'i18n', '~>0.6', '>= 0.6.11'
25
+ s.add_dependency 'fuzzy-string-match', '~>0.9', '>=0.9.7'
25
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdfmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.6
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Roos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-21 00:00:00.000000000 Z
11
+ date: 2015-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -90,6 +90,26 @@ dependencies:
90
90
  - - ">="
91
91
  - !ruby/object:Gem::Version
92
92
  version: 0.6.11
93
+ - !ruby/object:Gem::Dependency
94
+ name: fuzzy-string-match
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '0.9'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 0.9.7
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '0.9'
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 0.9.7
93
113
  description: |2
94
114
  Managing the common pdf metadata values and renaming the pdf file accordingly.
95
115
  Sets common tags like 'author', 'createdate', 'title', 'subject' and 'keywords'
@@ -122,6 +142,7 @@ files:
122
142
  - lib/pdfmd/explain.rb
123
143
  - lib/pdfmd/explain.subject.md
124
144
  - lib/pdfmd/explain.title.md
145
+ - lib/pdfmd/explain.typo.md
125
146
  - lib/pdfmd/long_desc.pdfmdclean.txt
126
147
  - lib/pdfmd/long_desc.pdfmdconfig.txt
127
148
  - lib/pdfmd/long_desc.pdfmdedit.txt
@@ -150,8 +171,8 @@ homepage: https://github.com/Micronarrativ/ruby-pmd
150
171
  licenses:
151
172
  - MIT
152
173
  metadata:
153
- created: '2015-09-21 21:06:09'
154
- revision: '20150921210609'
174
+ created: '2015-10-14 21:56:45'
175
+ revision: '20151014215645'
155
176
  post_install_message: ". Run `pdfmd` to see the command help."
156
177
  rdoc_options: []
157
178
  require_paths: