fixname 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/fixname.rb +44 -46
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9d1e38a2965557232e89243681a9253024c83277
|
|
4
|
+
data.tar.gz: d011d65cba970c32ef98a3454febaf63a4f9611f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c2467f5daf8e22bfee0b6d69bc1ed1530c882bc7057abf4b578cef0d0886e8bd5a2434af5742afd3f58ae3a6f1fb0b9a6e9e6a3257308809799f5ee2be09d4a5
|
|
7
|
+
data.tar.gz: e0ee0cd5fd414a90932b6c94ba980870d13b21632609f70a15b25cf95faa37a2d91806a5893c10883b76bc2be746ef3c313ad8cb240892be0a9ed2b772f4a7e4
|
data/lib/fixname.rb
CHANGED
|
@@ -1,26 +1,14 @@
|
|
|
1
1
|
#encoding: utf-8
|
|
2
2
|
# require "fixname/version"
|
|
3
3
|
|
|
4
|
-
# STDOUT.sync = true
|
|
5
|
-
# ARGV[0] = %q{I:\ebooks\english\_unsorted\A D Koboah - [Darkling 01] - Dark Genesis (mobi).mobi.epub}
|
|
6
|
-
|
|
7
4
|
module Fixname
|
|
8
5
|
|
|
9
|
-
def titleize
|
|
10
|
-
split(/(\W)/).map(&:capitalize).join
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def author
|
|
14
|
-
#return everything before the first -
|
|
15
|
-
self[/[^-]+/]
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def title
|
|
19
|
-
self.rpartition('-').last.partition('.').first.strip
|
|
6
|
+
def titleize string
|
|
7
|
+
string.split(/(\W)/).map(&:capitalize).join
|
|
20
8
|
end
|
|
21
9
|
|
|
22
10
|
def normalise
|
|
23
|
-
#
|
|
11
|
+
# replace spoecial characters with normal ones
|
|
24
12
|
begin
|
|
25
13
|
self.tr(
|
|
26
14
|
"#{}()'.,;_&0123456789ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž",
|
|
@@ -32,7 +20,7 @@ module Fixname
|
|
|
32
20
|
end
|
|
33
21
|
end
|
|
34
22
|
|
|
35
|
-
def
|
|
23
|
+
def check_filename file
|
|
36
24
|
basename = File.basename(file)
|
|
37
25
|
path = File.dirname(file)
|
|
38
26
|
ext = basename.rpartition('.').last.downcase
|
|
@@ -59,62 +47,72 @@ module Fixname
|
|
|
59
47
|
result.gsub!(/ *-*\./,".") #vervang spatie gevolgd door punt
|
|
60
48
|
result.gsub!(/ *- *$/,"") #vervang streepje aan het einde
|
|
61
49
|
result.strip!
|
|
62
|
-
result = result
|
|
50
|
+
result = titleize(result)
|
|
63
51
|
end
|
|
64
52
|
result = path+'/'+result+"."+ext
|
|
65
53
|
result.gsub('?',"'").gsub("./",'')
|
|
66
54
|
end
|
|
67
55
|
|
|
68
56
|
def rename old_name, new_name
|
|
69
|
-
puts %Q{ren "#{old_name}" "#{new_name}"}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
57
|
+
# puts %Q{ren "#{old_name}" "#{new_name}"}
|
|
58
|
+
puts new_name
|
|
59
|
+
system(%Q{move /y "#{old_name}" "#{new_name}"})
|
|
60
|
+
rescue => e
|
|
61
|
+
puts e
|
|
62
|
+
puts e.backtrace
|
|
73
63
|
end
|
|
74
64
|
|
|
75
|
-
def
|
|
65
|
+
def fix old_name
|
|
76
66
|
result = File.join(File.dirname(old_name), check_filename(File.basename(old_name))).gsub("/",'\\')
|
|
77
67
|
if old_name != result
|
|
78
68
|
old_name = old_name.gsub("/",'\\')
|
|
79
|
-
puts " #{old_name}"
|
|
80
|
-
puts "=>#{result}"
|
|
69
|
+
# puts " #{old_name}"
|
|
70
|
+
# puts "=>#{result}"
|
|
81
71
|
end
|
|
82
72
|
result
|
|
83
73
|
rescue => e
|
|
84
|
-
puts "Error while renaming #{old_name} to #{result}"
|
|
85
74
|
puts e
|
|
86
75
|
puts e.backtrace
|
|
87
|
-
puts
|
|
88
|
-
sleep 2 if $solo
|
|
89
76
|
end
|
|
90
77
|
|
|
91
|
-
def fixname
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
78
|
+
def fixname *paths
|
|
79
|
+
|
|
80
|
+
if paths
|
|
81
|
+
paths = [paths].flatten
|
|
82
|
+
elsif ARGV.length == 0
|
|
83
|
+
puts "No path given.."
|
|
84
|
+
abort "No path given.."
|
|
85
|
+
else
|
|
86
|
+
paths = ARGV
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
paths.each do |old_name|
|
|
90
|
+
if File.directory?(old_name)
|
|
91
|
+
old_name = old_name.gsub(/\\/,'/')
|
|
92
|
+
puts "#{old_name} is a folder\n"
|
|
93
|
+
Dir.glob("#{old_name}/*.*").each do |old_name|
|
|
94
|
+
begin
|
|
95
|
+
rename old_name, fix(old_name)
|
|
96
|
+
rescue => e
|
|
97
|
+
puts e
|
|
98
|
+
puts e.backtrace
|
|
99
|
+
sleep 2
|
|
100
|
+
end
|
|
102
101
|
end
|
|
102
|
+
else
|
|
103
|
+
rename old_name, fix(old_name)
|
|
103
104
|
end
|
|
104
|
-
else
|
|
105
|
-
old_name = self.dup
|
|
106
|
-
$solo = true
|
|
107
|
-
rename old_name, fix(old_name)
|
|
108
105
|
end
|
|
109
106
|
rescue => e
|
|
110
107
|
puts e
|
|
111
108
|
puts e.backtrace
|
|
112
|
-
sleep 2 if $solo
|
|
113
109
|
end
|
|
114
110
|
|
|
115
|
-
|
|
111
|
+
module_function :fix
|
|
112
|
+
module_function :fixname
|
|
113
|
+
module_function :check_filename
|
|
114
|
+
module_function :titleize
|
|
116
115
|
|
|
117
|
-
class String
|
|
118
|
-
include Fixname
|
|
119
116
|
end
|
|
120
117
|
|
|
118
|
+
|